home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap06 / howto02 / delphi10 / drwsutl4.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-01-04  |  128.9 KB  |  3,515 lines

  1. unit Drwsutl4;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, StdCtrls, Buttons, ExtCtrls, ShellAPI, FileCtrl, DRWSUtl1;
  8.  
  9. const
  10.   EOC_CHANGEDIR = 1;  { Error Operation Code for change directory failure }
  11.   EOC_SOURCECOPY = 2; { Error Operation Code for source copy failure      }
  12.   EOC_DESTCOPY = 3;   { Error Operation Code for destination copy failure }
  13.   EOC_DELETEFILE = 4; { Error Operation Code for file delete failure      }
  14.   EOC_DELETEDIR = 5;  { Error Operation Code for directory delete failure }
  15.   EOC_RENAMEFILE = 6; { Error Operation Code for renaming failure         }
  16.   EOC_MAKEDIR = 7;    { Error Operation Code for MkDir failure            }
  17.   EOC_SETATTR = 8;    { Error Operation Code for Set Attributes failure   }
  18.  
  19.   FAC_COPY = 1;       { File Action Code for recursive copying            }
  20.   FAC_MOVE = 2;       { File Action Code for recursive moving             }
  21.   FAC_DELETE = 3;     { File Action Code for recursive deletion           }
  22.  
  23.   KBMJ_SINGLE = 1;   { Keyboard mouse motion constant for single pixel moves }
  24.   KBMJ_SMALL = 10;    { Keyboard mouse motion constant for single pixel moves }
  25.   KBMJ_LARGE = 50;    { Keyboard mouse motion constant for single pixel moves }
  26.  
  27.   CR_KEYSET = 6; { ID for special keypress cursor }
  28.   CR_NULL = 7;   { ID for Null (blank) cursor     }
  29. type
  30.   { This is a descendant of TFileListbox }
  31.   { Which puts icons of files into the   }
  32.   { Objects array rather than the stand- }
  33.   { ard bitmaps.                         }
  34.   TIconFileListBox = class( TFileListBox )
  35.   public
  36.     { public methods and data }
  37.     procedure ReadFileNames; override;
  38.     function GetNextSelection( SourceDirectory : String;
  39.               var CurrentItem : Integer ) : String;
  40.     constructor Create(AOwner : TComponent); override; { override create    }
  41.     procedure TheDblClick( Sender : TObject );{ This holds override dblclick }
  42.   end;
  43.   TFileWorkBench = class( TComponent )
  44.   public
  45.     GlobalError        : Integer;  { This is used by FMXUCopyFile for er code }
  46.     GlobalErrorType    : Integer;  { This holds the Operation code            }
  47.     function ForceTrailingBackSlash( const TheFileName : String ) : String;
  48.     function StripNonRootTrailingBackSlash(
  49.               const TheFileName : String ) : String;
  50.     procedure GetFileAttributes( TheFile : String; var IsDirectory , IsArchive ,
  51.                 IsVolumeID , IsHidden , IsReadOnly , IsSysFile : Boolean );
  52.     procedure HandleIOException( TheOpCode : Integer; ThePath : String;
  53.                                  TheMessage : String; TheCode : Integer );
  54.     procedure HandleDOSError( TheOpCode : Integer; ThePath : String;
  55.                 TheCode : Integer );
  56.     function CopyFile( TargetPath ,
  57.                DestinationPath : String ) : Boolean;
  58.     procedure ChangeTheDirectory( NewPath : String );
  59.     procedure ChangeTheDriveAndDirectory( NewDrive : Integer );
  60.     procedure CopyTheFile( OldPath , NewPath : String );
  61.     procedure MoveTheFile( OldPath , NewPath : String );
  62.     procedure DeleteTheFile( ThePath : String );
  63.     procedure RenameTheFile( OldPath , NewName : String );
  64.     procedure CreateNewDirectory( NewPath : String );
  65.     procedure RemoveDirectory( ThePath : String );
  66.     procedure SetFileAttributes( TheFile  : String; TheAttributes : Integer );
  67.     procedure RecursivelyCopyDirectory( OldPath , NewPath : String );
  68.     procedure RecursivelyMoveDirectory( OldPath , NewPath : String );
  69.     procedure RecursivelyDeleteDirectory( ThePath : String );
  70.     procedure HandleRecursiveAction( StartingPath , NewPath : String;
  71.                ActionCode : Integer );
  72.   end;
  73.   TFileIconPanel = class( TPanel )
  74.   private
  75.     { Private declarations }
  76.     FHighlightColor : TColor;                 { This holds bright edge bevel }
  77.     FShadowColor    : TColor;                 { This holds dark edge bevel   }
  78.     procedure TheMouseDown(Sender: TObject;
  79.       Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  80.     procedure TheMouseMove( Sender: TObject; Shift: TShiftState;
  81.       X, Y: Integer);
  82.     procedure TheMouseUp(Sender: TObject;
  83.       Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  84.     procedure WMLButtonDblClk(var Message: TWMLButtonDblClk);
  85.      message WM_LBUTTONDBLCLK;
  86.     procedure TheDragOver(Sender, Source: TObject; X,
  87.       Y: Integer; State: TDragState; var Accept: Boolean);
  88.     procedure TheDragDrop(Sender, Source: TObject; X,
  89.       Y: Integer);
  90.   protected                                   { event method procedure.      }
  91.     { Protected declarations }
  92.     procedure Paint; override;                { This allows custom painting  }
  93.   public
  94.     { Public declarations }
  95.     FTheIcon : TIcon;                         { This is the display icon    }
  96.     FTheBMP  : TBitmap;                       { This holds a thumbnail image}
  97.     FTheName : String;                        { This is the filename        }
  98.     FTheLabel : TLabel;                       { This is the display label   }
  99.     Selected : Boolean;                       { This holds selection status }
  100.     constructor Create(AOwner : TComponent); override; { override create    }
  101.     procedure Initialize( PanelX              ,             { Left          }
  102.                           PanelY              ,             { Top           }
  103.                           PanelWidth          ,             { Width         }
  104.                           PanelHeight         ,             { Height        }
  105.                           PanelBevelWidth     ,             { Bevel Width   }
  106.                           LabelFontSize         : Integer;  { Font size     }
  107.                           PanelColor          ,             { Main color    }
  108.                           PanelHighlightColor ,             { Bright color  }
  109.                           PanelShadowColor    ,             { Dark color    }
  110.                           LabelTextColor        : TColor;   { Text color    }
  111.                           TheFilename         ,             { Filename      }
  112.                           LabelFontName         : String;   { Font name     }
  113.                           LabelFontStyle        : TFontStyles;  { Font style}
  114.                           ExtraData             : Integer       );  { Drive }
  115.     destructor Destroy; override;             { override destroy to free    }
  116.   end;
  117.   TFileIconPanelScrollBox = class( TScrollBox )
  118.   public
  119.     { Public methods and data }
  120.     TheFWB              : TFileWorkBench; { Used for file manipulation         }
  121.     IconsNeedRefreshing : Boolean;                   { Flag to redo display    }
  122.     TheIconSize        : Integer;   { Holds Individual Icon size               }
  123.     TheIconSpacing     : Integer;   { Holds total icon footprint               }
  124.     MaxIconsInARow     : Integer;   { Set for screen size.                     }
  125.     TheStoredHandle    : HWnd;
  126.     TheParentForm      : TForm;
  127.     procedure Update;                                { Called to reset display }
  128.     constructor Create( AOwner : TComponent ); override;  { Override inherited }
  129.     procedure ClearTheFIPs;                          { Clears the FIPs safely  }
  130.     procedure AddDriveIcons( var XCounter , YCounter : Integer ); { Add drives }
  131.     procedure GetColorsForFileIcon( TheFile : String;
  132.                var BC , HC , SC , TC : TColor );
  133.     procedure GetIconsForEntireDirectory( TargetPath  : String );
  134.     function GetNextSelection( SourceDirectory : String;
  135.               var CurrentItem : Integer ) : String;
  136.     procedure DisplayRecursiveSearchResults(
  137.       TheStartingDirectory : String );
  138.   end;
  139.   TIOManager = class( TComponent )
  140.   public
  141.     Parent : TForm;
  142.     WhichButton : TMouseButton;
  143.     WhichState  : TShiftState;
  144.     CLState ,
  145.     NLState ,
  146.     SLState   : Boolean;
  147.     function IsCapsLockDown : Boolean;
  148.     function ISNumLockDown : Boolean;
  149.     function IsScrollLockDown : Boolean;
  150.     procedure InitLocks;
  151.     procedure ReadLocks( var TheCL , TheNL , TheSL : Boolean );
  152.     procedure SetLocks( TheCL , TheNL , TheSL : Boolean );
  153.     function WasLeftPressed : Boolean;
  154.     function WasRightPressed : Boolean;
  155.     function WasMiddlePressed : Boolean;
  156.     function WasALTPressed : Boolean;
  157.     function WasSHIFTPressed : Boolean;
  158.     function WasCTRLPressed : Boolean;
  159.     procedure OnF1Pressed(Sender: TObject; var Key: Word;
  160.      Shift: TShiftState);
  161.     procedure OnF2Pressed(Sender: TObject; var Key: Word;
  162.      Shift: TShiftState);
  163.     procedure OnF3Pressed(Sender: TObject; var Key: Word;
  164.      Shift: TShiftState);
  165.     procedure OnF4Pressed(Sender: TObject; var Key: Word;
  166.      Shift: TShiftState);
  167.     procedure OnF5Pressed(Sender: TObject; var Key: Word;
  168.      Shift: TShiftState);
  169.     procedure OnF6Pressed(Sender: TObject; var Key: Word;
  170.      Shift: TShiftState);
  171.     procedure OnF7Pressed(Sender: TObject; var Key: Word;
  172.      Shift: TShiftState);
  173.     procedure OnF8Pressed(Sender: TObject; var Key: Word;
  174.      Shift: TShiftState);
  175.     procedure OnF9Pressed(Sender: TObject; var Key: Word;
  176.      Shift: TShiftState);
  177.     procedure OnF10Pressed(Sender: TObject; var Key: Word;
  178.      Shift: TShiftState);
  179.     procedure OnF11Pressed(Sender: TObject; var Key: Word;
  180.      Shift: TShiftState);
  181.     procedure OnF12Pressed(Sender: TObject; var Key: Word;
  182.      Shift: TShiftState);
  183.  end;
  184.  TMouseManager = class( TComponent )
  185.  public
  186.    TheMX : Integer;
  187.    TheMY : Integer;
  188.    Old_X ,
  189.    Old_Y ,
  190.    New_X ,
  191.    New_Y   : Integer;
  192.    StoredCursor : Integer;
  193.    BitmapCursor  : Boolean;
  194.    IconCursor    : Boolean;
  195.    CursorBMP     : TBitmap;
  196.    CursorIcon    : TIcon;
  197.    IsAnimated    : Boolean;
  198.    TheTimer      : TTimer;
  199.    TheAnimationList : TList;
  200.    CurrentAnimationPointer : Integer;
  201.    AnimationInterval : Integer;
  202.    SavedDC ,
  203.    GlobalDC : HDC;
  204.    GlobalCanvas : TCanvas;
  205.    WorkSpaceBMP : TBitmap;
  206.    BackGroundBMP : TBitmap;
  207.    constructor Create( AOwner : TComponent ); override;
  208.    destructor Destroy; override;
  209.    procedure InitializeNormal;
  210.    procedure InitializeBitmap( TheBmp : TBitmap );
  211.    procedure InitializeIcon( TheIcon : TIcon );
  212.    procedure InitializeAnimated( TheIcon : TIcon; TheInterval : Integer;
  213.                                  TheIconList : TList );
  214.    procedure GetMousePosition( var MouseX , MouseY : Integer );
  215.    procedure SetMousePosition( MouseX , MouseY : Integer );
  216.    procedure MoveSinglePixelLeft;
  217.    procedure MoveSinglePixelRight;
  218.    procedure MoveSinglePixelUp;
  219.    procedure MoveSinglePixelDown;
  220.    procedure MoveSmallJumpLeft;
  221.    procedure MoveSmallJumpRight;
  222.    procedure MoveSmallJumpUp;
  223.    procedure MoveSmallJumpDown;
  224.    procedure MoveLargeJumpLeft;
  225.    procedure MoveLargeJumpRight;
  226.    procedure MoveLargeJumpUp;
  227.    procedure MoveLargeJumpDown;
  228.    procedure StartBitmapCursor( TheX , TheY : Integer );
  229.    procedure MoveBitmapCursor( TheX , TheY : Integer );
  230.    procedure EndBitmapCursor( TheX , TheY : Integer );
  231.    procedure StartIconCursor( TheX , TheY : Integer );
  232.    procedure MoveIconCursor( TheX , TheY : Integer );
  233.    procedure EndIconCursor( TheX , TheY : Integer );
  234.    procedure StartAnimatedIconCursor( TheX , TheY : Integer );
  235.    procedure EndAnimatedIconCursor( TheX , TheY : Integer );
  236.    procedure MoveAnimatedIconCursor( TheX , TheY : Integer );
  237.    procedure TimerAction( Sender : TObject );
  238.  end;
  239.  
  240.   { This procedure gets an icon for a file using FindExecutable  }
  241.   { and ExtractIcon. (assumes file/dir is passed)                }
  242.   procedure GetIconForFile( TheName : String; var TheIcon : TIcon );
  243.   { This procedure spaces out the bitbtn components on a tpanel }
  244.   procedure SpacePanelButtons( WhichPanel : TPanel );
  245.     procedure FMXUCopyFile(const FileName, DestName: String; var GlobalErrorType ,
  246.                GlobalErrorCode : Integer );
  247.  
  248. var TheIOManager : TIOManager;
  249.     TheMouseManager : TMouseManager;
  250.     GlobalAbortFlag : Boolean;
  251.     SavedForm : TForm;
  252.     SavedControl : TFileIconPanel;
  253.     OtherSavedControl : TFileIconPanelScrollbox;
  254.     Savedhandle : HWnd;
  255.     IconDragging : boolean;
  256.     GlobalSource : TObject;
  257.     TheTempBitmap : TBitmap;
  258.     BitmapDragging : boolean;
  259.     ThumbNailWidth,
  260.     ThumbNailHeight : Integer;
  261.  
  262. implementation
  263. {$R DRWSUTL4.RES}                 { Import custom resource file }
  264. uses UFMGR31,DRWSUtl6;
  265.  
  266. { It has been edited to return viable error codes!             }
  267. procedure FMXUCopyFile(const FileName, DestName: String; var GlobalErrorType ,
  268.             GlobalErrorCode : Integer );
  269. var
  270.   CopyBuffer: Pointer; { buffer for copying }
  271.   BytesCopied: Longint;
  272.   TheAttr : Integer;
  273.   Source, Dest: Integer; { handles }
  274. const
  275.   ChunkSize: Longint = 8192; { copy in 8K chunks }
  276. begin
  277.   GetMem(CopyBuffer, ChunkSize); { allocate the buffer }
  278.   Source := FileOpen(FileName, fmShareDenyWrite); { open source file }
  279.   if Source < 0 then
  280.   begin  { error creating source file }
  281.     GlobalErrorType := EOC_SOURCECOPY;
  282.     GlobalErrorCode := -IOResult;
  283.     if GlobalErrorCode = 0 then GlobalErrorCode := -157;
  284.     FreeMem( CopyBuffer, ChunkSize );
  285.     exit;
  286.   end;
  287.   Dest := FileCreate(DestName); { create output file; overwrite existing }
  288.   if Dest < 0 then
  289.   begin  { error creating destination file }
  290.     FileClose( Source );
  291.     GlobalErrorType := EOC_DESTCOPY;
  292.     GlobalErrorCode := -IOResult;
  293.     if GlobalErrorCode = 0 then GlobalErrorCode := -159;
  294.     FreeMem( CopyBuffer , ChunkSize );
  295.     exit;
  296.   end;
  297.   {$I-}
  298.   repeat
  299.     BytesCopied := FileRead(Source, CopyBuffer^, ChunkSize); { read chunk}
  300.     if BytesCopied > 0 then { if we read anything... }
  301.     FileWrite(Dest, CopyBuffer^, BytesCopied); { ...write chunk }
  302.   until BytesCopied < ChunkSize; { until we run out of chunks }
  303.   {$I+}
  304.   GlobalErrorCode := -IOResult;  { get any error code which happens during copying }
  305.   FileClose(Dest); { close the destination file }
  306.   FileClose(Source); { close the source file }
  307.   FreeMem(CopyBuffer, ChunkSize); { free the buffer }
  308. end;
  309.  
  310. { This procedure spaces out the bitbtn components on a tpanel }
  311. procedure SpacePanelButtons( WhichPanel : TPanel );
  312. var TheCalculatedSpacing     ,            { Holds primary spacing }
  313.     TheFullCalculatedSpacing   : Integer; { Holds full spacing    }
  314.     Counter_1                  : Integer; { Loop counter          }
  315.     TotalIBs                   : Integer; { Gets total buttons    }
  316. begin
  317.   { Set up spacing values }
  318.   TotalIBs := WhichPanel.ControlCount;
  319.   TheCalculatedSpacing := (( WhichPanel.Width - 6 - ( TotalIbs * 49 ))
  320.    div ( TotalIbs + 1 ));
  321.   TheFullCalculatedSpacing := TheCalculatedSpacing + 49;
  322.   { Loop through all imported buttons and set their Left values }
  323.   for Counter_1 := 1 to WhichPanel.ControlCount do
  324.   begin
  325.     if Counter_1 = 1 then
  326.     begin
  327.       TBitBtn( WhichPanel.Controls[ Counter_1 - 1 ] ).Left := 3 +
  328.        TheCalculatedSpacing;
  329.     end
  330.     else
  331.     begin
  332.       TBitBtn( WhichPanel.Controls[ Counter_1 - 1 ] ).Left := 3 +
  333.        (( Counter_1 - 1 ) * TheFullCalculatedSpacing ) + TheCalculatedSpacing;
  334.     end;
  335.   end;
  336. end;
  337.  
  338. { This procedure gets an icon for a file using FindExecutable  }
  339. { and ExtractIcon. (assumes file/dir is passed)                }
  340. procedure GetIconForFile( TheName : String; var TheIcon : TIcon );
  341. var TheExt           : String; { File extension holder }
  342.     TheOtherPChar  ,           { Windows ASCIIZ string }
  343.     TheResultPChar ,           { Windows ASCIIZ string }
  344.     ThePChar         : PChar;  { Windows ASCIIZ string }
  345. begin
  346.   { Check for directory and if so get directory icon from RES file }
  347.   if (( FileGetAttr( TheName ) and faDirectory ) = faDirectory ) then
  348.   begin
  349.     { Set up the PChar to communicate with Windows }
  350.     GetMem( TheOtherPChar , 255 );
  351.     { Convert Pascal-style string to ASCIIZ Pchar }
  352.     StrPCopy( TheOtherPChar , 'DIRECTORY' );
  353.     { Use API call to return icon handle of Icon Resource in FILECTRL.RES }
  354.     TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  355.     { Release memory from PChar }
  356.     FreeMem( TheOtherPChar , 255 );
  357.     { Leave }
  358.     exit;
  359.   end;
  360.   { Assume archive file; get its extension }
  361.   TheExt := Uppercase( ExtractFileExt( TheName ));
  362.   { If not an executable/image file then use FindExecutable to get icon }
  363.   if (( TheExt <> '.EXE' ) and ( TheExt <> '.BAT' ) and
  364.       ( TheExt <> '.PIF' ) and ( TheExt <> '.COM' )) then
  365.   begin
  366.     { Grab three chunks of memory }
  367.     GetMem( TheOtherPChar , 255 );
  368.     GetMem( TheResultPChar , 255 );
  369.     GetMem( ThePChar , 255 );
  370.     { Set up the name and its directory in Windows string formats }
  371.     StrPCopy( ThePChar, TheName );
  372.     StrPCopy( TheOtherPChar , ExtractFilePath( TheName ));
  373.     { Use FindExecutable API call to get path and name of owning file }
  374.     if FindExecutable( ThePChar , TheOtherPChar , TheResultPChar ) > 31 then
  375.     begin
  376.       { If get a result of 32 or more then try to get first icon of owner }
  377.       { Using ExtractIcon API call; 0 indicates first icon.               }
  378.       TheIcon.Handle := ExtractIcon( hInstance , TheResultPchar , 0 );
  379.       { If a handle is 0 then no icon in owner, get default icon from RES file }
  380.       if TheIcon.Handle = 0 then
  381.       begin
  382.         GetMem( TheOtherPChar , 255 );
  383.         StrPCopy( TheOtherPChar , 'NOICON' );
  384.         TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  385.         FreeMem( TheOtherPChar , 255 );
  386.         exit;
  387.       end;
  388.     end
  389.     else
  390.     { if no assigned executable, then get default icon from RES file }
  391.     begin
  392.       GetMem( TheOtherPChar , 255 );
  393.       StrPCopy( TheOtherPChar , 'NOICON' );
  394.       TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  395.       FreeMem( TheOtherPChar , 255 );
  396.       exit;
  397.     end;
  398.     FreeMem( TheOtherPChar , 255 );
  399.     FreeMem( TheResultPChar , 255 );
  400.     FreeMem( ThePChar , 255 );
  401.   end
  402.   else
  403.   { Assume Windows Executable file, so get icon from it with ExtractIcon API }
  404.   begin
  405.     GetMem( ThePChar , 255 );
  406.     StrPCopy( ThePChar , TheName );
  407.     { If no icons in file then get default icon (note use FFFF for -1) }
  408.     if ExtractIcon( hInstance , ThePchar , 65535 ) = 0 then
  409.     begin
  410.       Freemem( ThePChar , 255 );
  411.       GetMem( TheOtherPChar , 255 );
  412.       StrPCopy( TheOtherPChar , 'NOICON' );
  413.       TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  414.       FreeMem( TheOtherPChar , 255 );
  415.       exit;
  416.     end
  417.     else
  418.     begin
  419.       { Try to get first icon for file }
  420.       TheIcon.Handle := ExtractIcon( hInstance , ThePChar , 0 );
  421.       FreeMem( ThePChar , 255 );
  422.       { If handle is 0 invalid icon format so use default from RES file }
  423.       if TheIcon.Handle = 0 then
  424.       begin
  425.         GetMem( TheOtherPChar , 255 );
  426.         StrPCopy( TheOtherPChar , 'NOICON' );
  427.         TheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  428.         FreeMem( TheOtherPChar , 255 );
  429.         exit;
  430.       end;
  431.     end;
  432.   end;
  433. end;
  434.  
  435. { This creates the TMouseManager and inits vars to null }
  436. constructor TMouseManager.Create( AOwner : TComponent );
  437. begin
  438.   { Call inherited FIRST! }
  439.   inherited Create( AOwner );
  440.   { Set all variables to 0 , false or nil }
  441.   TheMX := 0;
  442.   TheMY := 0;
  443.   Old_X  := 0;
  444.   Old_Y  := 0;
  445.   New_X  := 0;
  446.   New_Y  := 0;
  447.   StoredCursor := 0;
  448.   BitmapCursor  := false;
  449.   IconCursor    := false;
  450.   CursorBMP     := nil;
  451.   CursorIcon    := nil;
  452.   IsAnimated    := false;
  453.   TheTimer      := nil;
  454.   TheAnimationList := nil;
  455.   CurrentAnimationPointer := 0;
  456.   AnimationInterval := 0;
  457.   SavedDC := 0;
  458.   GlobalDC := 0;
  459.   GlobalCanvas := nil;
  460.   WorkSpaceBMP := nil;
  461.   BackGroundBMP := nil;
  462. end;
  463.  
  464. { This destroys the tmousemanager and releases all resources }
  465. destructor TMouseManager.Destroy;
  466. begin
  467.   { Free any assigned resources (the moving bmp ones already are gone) }
  468.   if assigned( TheTimer ) then
  469.    TheTimer.Free;
  470.   if assigned( TheAnimationList ) then
  471.    TheAnimationList.Free;
  472.   Inherited Destroy;
  473. end;
  474.  
  475. { This sets up the mouse manager for normal cursor operations }
  476. procedure TMouseManager.InitializeNormal;
  477. var TheMP : TPoint;
  478. begin
  479.   { Reset State Variables }
  480.   BitmapCursor := false;
  481.   IconCursor := false;
  482.   IsAnimated := false;
  483.   { Call API to get mouse coordinates }
  484.   GetCursorPos( TheMP );
  485.   { Store the coordinates for later use }
  486.   TheMX := TheMP.X;
  487.   TheMY := TheMP.Y;
  488.   Old_X := TheMX;
  489.   Old_Y := TheMY;
  490.   New_X := TheMX;
  491.   New_Y := TheMY;
  492. end;
  493.  
  494. { This procedure initializes a bitmap cursor }
  495. procedure TMouseManager.InitializeBitmap( TheBmp : TBitmap );
  496. begin
  497.   InitializeNormal;
  498.   CursorBMP := TheBMP;
  499.   BitmapCursor := true;
  500. end;
  501.  
  502. { This procedure initalizes an icon cursor }
  503. procedure TMouseManager.InitializeIcon( TheIcon : TIcon );
  504. begin
  505.   InitializeNormal;
  506.   CursorIcon := TheIcon;
  507.   IconCursor := true;
  508. end;
  509.  
  510. { This procedure initializes an animated icon cursor }
  511. procedure TMouseManager.InitializeAnimated( TheIcon : TIcon;
  512.            TheInterval : Integer; TheIconList : TList );
  513. begin
  514.   InitializeNormal;
  515.   CursorIcon := TheIcon;
  516.   IconCursor := true;
  517.   IsAnimated := true;
  518.   AnimationInterval := TheInterval;
  519.   TheAnimationList := TheIconList;
  520.   TheTimer := TTimer.Create( Self );
  521.   TheTimer.Enabled := false;
  522.   TheTimer.Interval := AnimationInterval;
  523.   TheTimer.OnTimer := TimerAction;
  524. end;
  525.  
  526. { This procedure returns the current stored mouse position }
  527. procedure TMouseManager.GetMousePosition( var MouseX , MouseY : Integer );
  528. begin
  529.   { Return stored position rather than call API }
  530.   MouseX := TheMX;
  531.   MouseY := TheMY;
  532. end;
  533.  
  534. { This procedure sets the Mouse Position internally }
  535. procedure TMouseManager.SetMousePosition( MouseX , MouseY : Integer );
  536. begin
  537.   { Set internal coordinates; don't call API }
  538.   TheMX := MouseX;
  539.   TheMY := MouseY;
  540. end;
  541.  
  542. { This procedure is used to drive the mouse with the keyboard }
  543. procedure TMouseManager.MoveSinglePixelLeft;
  544. begin
  545.   { Use internal coordinates and check for screen wrapping }
  546.   if TheMX > KBMJ_SINGLE then
  547.   begin
  548.     { Not wrapped; move along one unit to the left }
  549.     TheMX := TheMX - KBMJ_SINGLE;
  550.     SetCursorPos( TheMX , TheMY );
  551.   end
  552.   else
  553.   begin
  554.     { Wrapped; jump to right and move back one unit }
  555.     TheMX := Screen.Width - KBMJ_SINGLE;
  556.     SetCursorPos( TheMX , TheMY );
  557.   end;
  558. end;
  559.  
  560. { This procedure is used to drive the mouse with the keyboard }
  561. procedure TMouseManager.MoveSinglePixelRight;
  562. begin
  563.   { Use internal coordinates and check for screen wrapping }
  564.   if TheMX < ( Screen.Width - KBMJ_SINGLE ) then
  565.   begin
  566.     { Not wrapped; move along one unit to the right }
  567.     TheMX := TheMX + KBMJ_SINGLE;
  568.     SetCursorPos( TheMX , TheMY );
  569.   end
  570.   else
  571.   begin
  572.     { Wrapped; jump to left and move in one unit }
  573.     TheMX := KBMJ_SINGLE;
  574.     SetCursorPos( TheMX , TheMY );
  575.   end;
  576. end;
  577.  
  578. { This procedure is used to drive the mouse with the keyboard }
  579. procedure TMouseManager.MoveSinglePixelUp;
  580. begin
  581.   { Use internal coordinates and check for screen wrapping }
  582.   if TheMY > KBMJ_SINGLE then
  583.   begin
  584.     { Not wrapped; move along one unit to the top }
  585.     TheMY := TheMY - KBMJ_SINGLE;
  586.     SetCursorPos( TheMX , TheMY );
  587.   end
  588.   else
  589.   begin
  590.     { Wrapped; jump to bottom and move back one unit }
  591.     TheMY := Screen.Height - KBMJ_SINGLE;
  592.     SetCursorPos( TheMX , TheMY );
  593.   end;
  594. end;
  595.  
  596. { This procedure is used to drive the mouse with the keyboard }
  597. procedure TMouseManager.MoveSinglePixelDown;
  598. begin
  599.   { Use internal coordinates and check for screen wrapping }
  600.   if TheMY < ( Screen.Height - KBMJ_SINGLE ) then
  601.   begin
  602.     { Not wrapped; move along one unit to the bottom }
  603.     TheMY := TheMY + KBMJ_SINGLE;
  604.     SetCursorPos( TheMX , TheMY );
  605.   end
  606.   else
  607.   begin
  608.     { Wrapped; jump to top and move back one unit }
  609.     TheMY := KBMJ_SINGLE;
  610.     SetCursorPos( TheMX , TheMY );
  611.   end;
  612. end;
  613.  
  614. { This procedure is used to drive the mouse with the keyboard }
  615. procedure TMouseManager.MoveSmallJumpLeft;
  616. begin
  617.   { Use internal coordinates and check for screen wrapping }
  618.   if TheMX > KBMJ_SMALL then
  619.   begin
  620.     { Not wrapped; move along one unit to the left }
  621.     TheMX := TheMX - KBMJ_SMALL;
  622.     SetCursorPos( TheMX , TheMY );
  623.   end
  624.   else
  625.   begin
  626.     { Wrapped; jump to right and move back the unit }
  627.     TheMX := Screen.Width - KBMJ_SMALL;
  628.     SetCursorPos( TheMX , TheMY );
  629.   end;
  630. end;
  631.  
  632. { This procedure is used to drive the mouse with the keyboard }
  633. procedure TMouseManager.MoveSmallJumpRight;
  634. begin
  635.   { Use internal coordinates and check for screen wrapping }
  636.   if TheMX < ( Screen.Width - KBMJ_SMALL ) then
  637.   begin
  638.     { Not wrapped; move along one unit to the right }
  639.     TheMX := TheMX + KBMJ_SMALL;
  640.     SetCursorPos( TheMX , TheMY );
  641.   end
  642.   else
  643.   begin
  644.     { Wrapped; jump to left and move in one unit }
  645.     TheMX := KBMJ_SMALL;
  646.     SetCursorPos( TheMX , TheMY );
  647.   end;
  648. end;
  649.  
  650. { This procedure is used to drive the mouse with the keyboard }
  651. procedure TMouseManager.MoveSmallJumpUp;
  652. begin
  653.   { Use internal coordinates and check for screen wrapping }
  654.   if TheMY > KBMJ_SMALL then
  655.   begin
  656.     { Not wrapped; move along one unit to the top }
  657.     TheMY := TheMY - KBMJ_SMALL;
  658.     SetCursorPos( TheMX , TheMY );
  659.   end
  660.   else
  661.   begin
  662.     { Wrapped; jump to bottom and move back one unit }
  663.     TheMY := Screen.Height - KBMJ_SMALL;
  664.     SetCursorPos( TheMX , TheMY );
  665.   end;
  666. end;
  667.  
  668. { This procedure is used to drive the mouse with the keyboard }
  669. procedure TMouseManager.MoveSmallJumpDown;
  670. begin
  671.   { Use internal coordinates and check for screen wrapping }
  672.   if TheMY < ( Screen.Height - KBMJ_SMALL ) then
  673.   begin
  674.     { Not wrapped; move along one unit to the bottom }
  675.     TheMY := TheMY + KBMJ_SMALL;
  676.     SetCursorPos( TheMX , TheMY );
  677.   end
  678.   else
  679.   begin
  680.     { Wrapped; jump to top and move back one unit }
  681.     TheMY := KBMJ_SMALL;
  682.     SetCursorPos( TheMX , TheMY );
  683.   end;
  684. end;
  685.  
  686. { This procedure is used to drive the mouse with the keyboard }
  687. procedure TMouseManager.MoveLargeJumpLeft;
  688. begin
  689.   { Use internal coordinates and check for screen wrapping }
  690.   if TheMX > KBMJ_LARGE then
  691.   begin
  692.     { Not wrapped; move along the unit to the left }
  693.     TheMX := TheMX - KBMJ_LARGE;
  694.     SetCursorPos( TheMX , TheMY );
  695.   end
  696.   else
  697.   begin
  698.     { Wrapped; jump to right and move back the unit }
  699.     TheMX := Screen.Width - KBMJ_LARGE;
  700.     SetCursorPos( TheMX , TheMY );
  701.   end;
  702. end;
  703.  
  704. { This procedure is used to drive the mouse with the keyboard }
  705. procedure TMouseManager.MoveLargeJumpRight;
  706. begin
  707.   { Use internal coordinates and check for screen wrapping }
  708.   if TheMX < ( Screen.Width - KBMJ_LARGE ) then
  709.   begin
  710.     { Not wrapped; move along one unit to the right }
  711.     TheMX := TheMX + KBMJ_LARGE;
  712.     SetCursorPos( TheMX , TheMY );
  713.   end
  714.   else
  715.   begin
  716.     { Wrapped; jump to left and move in one unit }
  717.     TheMX := KBMJ_LARGE;
  718.     SetCursorPos( TheMX , TheMY );
  719.   end;
  720. end;
  721.  
  722. { This procedure is used to drive the mouse with the keyboard }
  723. procedure TMouseManager.MoveLargeJumpUp;
  724. begin
  725.   { Use internal coordinates and check for screen wrapping }
  726.   if TheMY > KBMJ_LARGE then
  727.   begin
  728.     { Not wrapped; move along one unit to the top }
  729.     TheMY := TheMY - KBMJ_LARGE;
  730.     SetCursorPos( TheMX , TheMY );
  731.   end
  732.   else
  733.   begin
  734.     { Wrapped; jump to bottom and move back one unit }
  735.     TheMY := Screen.Height - KBMJ_LARGE;
  736.     SetCursorPos( TheMX , TheMY );
  737.   end;
  738. end;
  739.  
  740. { This procedure is used to drive the mouse with the keyboard }
  741. procedure TMouseManager.MoveLargeJumpDown;
  742. begin
  743.   { Use internal coordinates and check for screen wrapping }
  744.   if TheMY < ( Screen.Height - KBMJ_LARGE ) then
  745.   begin
  746.     { Not wrapped; move along one unit to the bottom }
  747.     TheMY := TheMY + KBMJ_LARGE;
  748.     SetCursorPos( TheMX , TheMY );
  749.   end
  750.   else
  751.   begin
  752.     { Wrapped; jump to top and move back one unit }
  753.     TheMY := KBMJ_LARGE;
  754.     SetCursorPos( TheMX , TheMY );
  755.   end;
  756. end;
  757.  
  758. { This procedure sets up the bitmaps and global HDC prior to moving a }
  759. { Bitmap cursor.                                                      }
  760. procedure TMouseManager.StartBitmapCursor( TheX , TheY : Integer );
  761. var WorkingPoint1 ,
  762.     WorkingPoint2 : TPoint;
  763. begin
  764.   GlobalDC := GetDC( 0 );
  765.   WorkspaceBMP := TBitmap.Create;
  766.   WorkspaceBMP.Width := Screen.Width;
  767.   WorkSpaceBMP.Height := Screen.Height;
  768.   BitBlt( WorkspaceBMP.Canvas.Handle , 0 , 0 , Screen.Width , Screen.Height ,
  769.    GlobalDC , 0 , 0 , SrcCopy );
  770.   BackgroundBMP := TBitmap.Create;
  771.   BackgroundBMP.Width := CursorBMP.Width;
  772.   BackgroundBMP.Height := CursorBMP.Height;
  773.   New_X := TheX;
  774.   New_Y := TheY;
  775.   StoredCursor := Screen.Cursor;
  776.   Screen.Cursor := CR_NULL;
  777.   {Grab the background image}
  778.   WorkingPoint1.X := New_X - ( CursorBMP.Width div 2 );
  779.   WorkingPoint1.Y := New_Y - ( CursorBMP.Height div 2 );
  780.   WorkingPoint2.X := New_X + ( CursorBMP.Width - ( CursorBMP.Width div 2 ));
  781.   WorkingPoint2.Y := New_Y + ( CursorBMP.Height - ( CursorBMP.Height div 2 ));
  782.   BackgroundBmp.Canvas.CopyRect( Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ) ,
  783.    WorkspaceBMP.Canvas , Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X ,
  784.     WorkingPoint2.Y ));
  785.   {Put the cursor bitmap onto the workspace canvas}
  786.   with WorkspaceBMP.Canvas do
  787.   begin
  788.     CopyMode := cmSrcCopy;
  789.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  790.      CursorBMP.Canvas , Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ));
  791.   end;
  792.   {Copy the workspace bitmap onto the visible screen}
  793.     BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , CursorBMP.Width , CursorBMP.Height ,
  794.      WorkspaceBMP.Canvas.Handle , WorkingPoint1.X , WorkingPoint1.Y , SrcCopy );
  795.   Old_X := New_X;
  796.   Old_Y := New_Y;
  797. end;
  798.  
  799. { This procedure moves a bitmap cursor according to the imported New coords }
  800. procedure TMouseManager.MoveBitmapCursor( TheX , TheY : Integer );
  801. var StartX,
  802.     StartY,
  803.     XDiff,
  804.     YDiff : Integer;
  805.     WorkingPoint1 ,
  806.     WorkingPoint2  : TPoint;
  807. begin
  808.   New_X := TheX;
  809.   New_Y := TheY;
  810.   WorkingPoint1.X := Old_X - ( CursorBMP.Width div 2 );
  811.   WorkingPoint1.Y := Old_Y - ( CursorBMP.Height div 2 );
  812.   WorkingPoint2.X := Old_X + ( CursorBMP.Width - ( CursorBMP.Width div 2 ));
  813.   WorkingPoint2.Y := Old_Y + ( CursorBMP.Height - ( CursorBMP.Height div 2 ));
  814.   with WorkspaceBMP.Canvas do
  815.   begin
  816.     CopyMode := cmSrcCopy;
  817.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  818.       BackgroundBMP.Canvas , Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ));
  819.   end;
  820.   {Put the saved bitmap onto the workspace canvas}
  821.   with WorkspaceBMP.Canvas do
  822.   begin
  823.     CopyMode := cmSrcCopy;
  824.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  825.      BackgroundBMP.Canvas , Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ));
  826.   end;
  827.   {Grab the background image}
  828.   WorkingPoint1.X := New_X - ( CursorBMP.Width div 2 );
  829.   WorkingPoint1.Y := New_Y - ( CursorBMP.Height div 2 );
  830.   WorkingPoint2.X := New_X + ( CursorBMP.Width - ( CursorBMP.Width div 2 ));
  831.   WorkingPoint2.Y := New_Y + ( CursorBMP.Height - ( CursorBMP.Height div 2 ));
  832.   BackgroundBmp.Canvas.CopyRect( Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ) ,
  833.    WorkspaceBMP.Canvas , Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X ,
  834.     WorkingPoint2.Y ));
  835.   {Put the cursor bitmap onto the workspace canvas}
  836.   with WorkspaceBMP.Canvas do
  837.   begin
  838.     CopyMode := cmSrcCopy;
  839.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  840.      CursorBMP.Canvas , Rect( 0 , 0 , CursorBMP.Width , CursorBMP.Height ));
  841.   end;
  842.   {Copy the workspace bitmap onto the visible screen}
  843.   if New_X > Old_X then StartX := Old_X else StartX := New_X;
  844.   if New_Y > Old_Y then StartY := Old_Y else StartY := New_Y;
  845.   XDiff := Abs( Old_X - New_X );
  846.   YDiff := Abs( Old_Y - New_Y );
  847.   {Grab the background image}
  848.   WorkingPoint1.X := StartX - ( CursorBMP.Width div 2 );
  849.   WorkingPoint1.Y := StartY - ( CursorBMP.Height div 2 );
  850.   BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , CursorBMP.Width + XDiff ,
  851.    CursorBMP.Height + YDiff , WorkspaceBMP.Canvas.Handle , WorkingPoint1.X ,
  852.     WorkingPoint1.Y , SrcCopy );
  853.   Old_X := New_X;
  854.   Old_Y := New_Y;
  855. end;
  856.  
  857. { This procedure releases a bitmap cursor and frees its DC }
  858. procedure TMouseManager.EndBitmapCursor( TheX , TheY : Integer );
  859. var WorkingPoint1 ,
  860.     WorkingPoint2 : TPoint;
  861. begin
  862.   BitmapCursor := false;
  863.   WorkingPoint1.X := Old_X - ( CursorBMP.Width div 2 );
  864.   WorkingPoint1.Y := Old_Y - ( CursorBMP.Height Div 2 );
  865.   WorkingPoint2.X := Old_X + ( CursorBMP.Width - ( CursorBMP.Width div 2 ));
  866.   WorkingPoint2.Y := Old_Y + ( CursorBMP.Height - ( CursorBMP.Height div 2 ));
  867.   {Put the saved bitmap onto the workspace canvas}
  868.   with WorkspaceBMP.Canvas do
  869.   begin
  870.     CopyMode := cmSrcCopy;
  871.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  872.        BackGroundBMP.Canvas , Rect( 0 , 0 , CursorBMP.Width ,  CursorBMP.Height ));
  873.   end;
  874.   {Copy the workspace bitmap onto the visible screen}
  875.   BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , CursorBMP.Width , CursorBMP.Height ,
  876.    WorkspaceBMP.Canvas.handle , WorkingPoint1.X , WorkingPoint1.Y , SrcCopy );
  877.   ReleaseDC( 0 , GlobalDC );
  878.   Screen.Cursor := StoredCursor;
  879. end;
  880.  
  881. { This procedure starts the process of displaying an icon cursor }
  882. procedure TMouseManager.StartIconCursor( TheX , TheY : Integer );
  883. var WorkingPoint1 ,
  884.     WorkingPoint2 : TPoint;
  885. begin
  886.   GlobalDC := GetDC( 0 );
  887.   WorkspaceBMP := TBitmap.Create;
  888.   WorkspaceBMP.Width := Screen.Width;
  889.   WorkSpaceBMP.Height := Screen.Height;
  890.   BitBlt( WorkspaceBMP.Canvas.Handle , 0 , 0 , Screen.Width , Screen.Height ,
  891.    GlobalDC , 0 , 0 , SrcCopy );
  892.   BackgroundBMP := TBitmap.Create;
  893.   BackgroundBMP.Width := 33;
  894.   BackgroundBMP.Height := 33;
  895.   New_X := TheX;
  896.   New_Y := TheY;
  897.   StoredCursor := Screen.Cursor;
  898.   Screen.Cursor := CR_NULL;
  899.   {Grab the background image}
  900.   WorkingPoint1.X := New_X - 16;
  901.   WorkingPoint1.Y := New_Y - 16;
  902.   WorkingPoint2.X := New_X + 17;
  903.   WorkingPoint2.Y := New_Y + 17;
  904.   BackgroundBmp.Canvas.CopyRect( Rect( 0 , 0 , 33 , 33 ) , WorkspaceBMP.Canvas ,
  905.      Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ));
  906.   {Put the icon onto the workspace canvas}
  907.   with WorkspaceBMP.Canvas do
  908.   begin
  909.     Draw( WorkingPoint1.X , WorkingPoint1.Y , CursorIcon );
  910.   end;
  911.   {Copy the workspace bitmap onto the visible screen}
  912.     BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , 33 , 33 ,
  913.      WorkspaceBMP.Canvas.Handle , WorkingPoint1.X , WorkingPoint1.Y , SrcCopy );
  914.   Old_X := New_X;
  915.   Old_Y := New_Y;
  916. end;
  917.  
  918. { This procedure moves the icon cursor in response to mouse moves }
  919. procedure TMouseManager.MoveIconCursor( TheX , TheY : Integer );
  920. var StartX,
  921.     StartY,
  922.     XDiff,
  923.     YDiff : Integer;
  924.     WorkingPoint1 ,
  925.     WorkingPoint2  : TPoint;
  926. begin
  927.   New_X := TheX;
  928.   New_Y := TheY;
  929.   {Put the saved bitmap onto the workspace canvas}
  930.   WorkingPoint1.X := Old_X - 16;
  931.   WorkingPoint1.Y := Old_Y - 16;
  932.   WorkingPoint2.X := Old_X + 17;
  933.   WorkingPoint2.Y := Old_Y + 17;
  934.   with WorkspaceBMP.Canvas do
  935.   begin
  936.     CopyMode := cmSrcCopy;
  937.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  938.       BackgroundBMP.Canvas , Rect( 0 , 0 , 33 , 33 ));
  939.   end;
  940.   {Grab the background image}
  941.   WorkingPoint1.X := New_X - 16;
  942.   WorkingPoint1.Y := New_Y - 16;
  943.   WorkingPoint2.X := New_X + 17;
  944.   WorkingPoint2.Y := New_Y + 17;
  945.   BackgroundBMP.Canvas.CopyRect( Rect( 0 , 0 , 33 , 33 ) , WorkspaceBMP.Canvas ,
  946.      Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ));
  947.   {Put the icon onto the workspace canvas}
  948.   with WorkspaceBMP.Canvas do
  949.   begin
  950.     Draw( WorkingPoint1.X , WorkingPoint1.Y , CursorIcon );
  951.   end;
  952.   {Copy the workspace bitmap onto the visible screen}
  953.     if New_X > Old_X then StartX := Old_X else StartX := New_X;
  954.     if New_Y > Old_Y then StartY := Old_Y else StartY := New_Y;
  955.     XDiff := Abs( Old_X - New_X );
  956.     YDiff := Abs( Old_Y - New_Y );
  957.     {Grab the background image}
  958.     WorkingPoint1.X := StartX - 16;
  959.     WorkingPoint1.Y := StartY - 16;
  960.     BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , 33 + XDiff , 33 + YDiff ,
  961.      WorkspaceBMP.Canvas.Handle , WorkingPoint1.X , WorkingPoint1.Y , SrcCopy );
  962.   Old_X := New_X;
  963.   Old_Y := New_Y;
  964. end;
  965.  
  966. { This procedure ends the icon cursor movement and frees its DCs }
  967. procedure TMouseManager.EndIconCursor( TheX , TheY : Integer );
  968. var WorkingPoint1 ,
  969.     WorkingPoint2 : TPoint;
  970. begin
  971.   IconCursor := false;
  972.   WorkingPoint1.X := Old_X - 16;
  973.   WorkingPoint1.Y := Old_Y - 16;
  974.   WorkingPoint2.X := Old_X + 17;
  975.   WorkingPoint2.Y := Old_Y + 17;
  976.   {Put the saved bitmap onto the workspace canvas}
  977.   with WorkspaceBMP.Canvas do
  978.   begin
  979.     CopyMode := cmSrcCopy;
  980.     CopyRect( Rect( WorkingPoint1.X , WorkingPoint1.Y , WorkingPoint2.X , WorkingPoint2.Y ),
  981.        BackGroundBMP.Canvas , Rect( 0 , 0 , 33 ,  33 ));
  982.   end;
  983.   {Copy the workspace bitmap onto the visible screen}
  984.   BitBlt( GlobalDC , WorkingPoint1.X , WorkingPoint1.Y , 33 , 33 ,
  985.    WorkspaceBMP.Canvas.handle , WorkingPoint1.X , WorkingPoint1.Y , SrcCopy );
  986.   ReleaseDC( 0 , GlobalDC );
  987.   Screen.Cursor := StoredCursor;
  988. end;
  989.  
  990. { This procedure starts the animated icon cursor }
  991. procedure TMouseManager.StartAnimatedIconCursor( TheX , TheY : Integer );
  992. begin
  993.   StartIconCursor( TheX , TheY );
  994.   TheTimer.Enabled := true;
  995.   CurrentAnimationPointer := 1;
  996. end;
  997.  
  998. { This procedue ends the animated icon cursor }
  999. procedure TMouseManager.EndAnimatedIconCursor( TheX , TheY : Integer );
  1000. begin
  1001.   EndIconCursor( TheX , TheY );
  1002.   TheTimer.Enabled := false;
  1003.   CursorIcon := TIcon( TheAnimationList[ 0 ] );
  1004. end;
  1005.  
  1006. { This procedure moves the animated icon cursor }
  1007. procedure TMouseManager.MoveAnimatedIconCursor( TheX , TheY : Integer );
  1008. begin
  1009.   MoveIconCursor( TheX , TheY );
  1010. end;
  1011.  
  1012. { This procedure switches icons on timer events and prompts a redraw }
  1013. procedure TMouseManager.TimerAction( Sender : TObject );
  1014. begin
  1015.   Inc( CurrentAnimationPointer );     
  1016.   if CurrentAnimationPointer > TheAnimationList.Count then
  1017.    CurrentAnimationPointer := 1;
  1018.   CursorIcon := TIcon( TheAnimationList[ CurrentAnimationPointer - 1 ] );
  1019.   MoveIconCursor( Old_X , Old_Y );
  1020. end;
  1021.  
  1022. { This function returns true if CAPSLOCK is down }
  1023. function TIoManager.IsCapsLockDown : Boolean;
  1024. begin
  1025.   if CLState then result := true else result := false;
  1026. end;
  1027.  
  1028. { This function returns true if NUMLOCK is down }
  1029. function TIoManager.ISNumLockDown : Boolean;
  1030. begin
  1031.   if NLState then result := true else result := false;
  1032. end;
  1033.  
  1034. { This function returns true if SCROLLLOCK is down }
  1035. function TIoManager.IsScrollLockDown : Boolean;
  1036. begin
  1037.   if SLState then result := true else result := false;
  1038. end;
  1039.  
  1040. { this function gets the values for CLState, NLState, and SLState }
  1041. procedure TIoManager.InitLocks;
  1042. var TheKeys : TKeyboardState;
  1043. begin
  1044.   GetKeyBoardState( TheKeys );
  1045.   CLState := (( TheKeys[ VK_Capital ] mod 2 ) = 1 );
  1046.   NLState := (( TheKeys[ VK_Numlock ] mod 2 ) = 1 );
  1047.   CLState := (( TheKeys[ VK_Scroll ] mod 2 ) = 1 );
  1048. end;
  1049.  
  1050. { This procedure returns the state of the three lock variables }
  1051. procedure TIoManager.ReadLocks( var TheCL , TheNL , TheSL : Boolean );
  1052. begin
  1053.   TheCL := CLState;
  1054.   TheNL := NLState;
  1055.   TheSL := SLState;
  1056. end;
  1057.  
  1058. { This procedure sets the state of the three lock variables to the imported vals }
  1059. procedure TIoManager.SetLocks( TheCL , TheNL , TheSL : Boolean );
  1060. var TheKeys : TKeyBoardState;
  1061. begin
  1062.   GetKeyBoardState( TheKeys );
  1063.   CLState := TheCL;
  1064.   NLState := TheNL;
  1065.   SLState := TheSL;
  1066.   if ClState then TheKeys[ VK_Capital ] := 1 else
  1067.    TheKeys[ VK_Capital ] := 0;
  1068.   if NLState then TheKeys[ VK_Numlock ] := 1 else
  1069.    TheKeys[ VK_Numlock ] := 0;
  1070.   if SLState then TheKeys[ VK_Scroll ] := 1 else
  1071.    TheKeys[ VK_Scroll ] := 0;
  1072.   SetKeyBoardState( TheKeys );
  1073. end;
  1074.  
  1075. { This procedure handles pressing of F1 for CCFileManagerForm }
  1076. procedure TIoManager.OnF1Pressed(Sender: TObject; var Key: Word;
  1077.   Shift: TShiftState);
  1078. begin
  1079.   MessageDlg( 'Help not implemented!' , mtInformation,[mbok],0);
  1080. end;
  1081.  
  1082. { This procedure handles pressing of F2 for CCFileManagerForm }
  1083. procedure TIoManager.OnF2Pressed(Sender: TObject; var Key: Word;
  1084.   Shift: TShiftState);
  1085. begin
  1086.   TCCFileMgrForm( Parent ).BitBtn1Click( Sender );
  1087. end;
  1088.  
  1089. { This procedure handles pressing of F3 for CCFileManagerForm }
  1090. procedure TIoManager.OnF3Pressed(Sender: TObject; var Key: Word;
  1091.   Shift: TShiftState);
  1092. begin
  1093.   TCCFileMgrForm( Parent ).BitBtn2Click( Sender );
  1094. end;
  1095.  
  1096. { This procedure handles pressing of F4 for CCFileManagerForm }
  1097. procedure TIoManager.OnF4Pressed(Sender: TObject; var Key: Word;
  1098.   Shift: TShiftState);
  1099. begin
  1100.   TCCFileMgrForm( Parent ).BitBtn3Click( Sender );
  1101. end;
  1102.  
  1103. { This procedure handles pressing of F5 for CCFileManagerForm }
  1104. procedure TIoManager.OnF5Pressed(Sender: TObject; var Key: Word;
  1105.   Shift: TShiftState);
  1106. begin
  1107.   TCCFileMgrForm( Parent ).BitBtn4Click( Sender );
  1108. end;
  1109.  
  1110. { This procedure handles pressing of F6 for CCFileManagerForm }
  1111. procedure TIoManager.OnF6Pressed(Sender: TObject; var Key: Word;
  1112.   Shift: TShiftState);
  1113. begin
  1114.   TCCFileMgrForm( Parent ).BitBtn5Click( Sender );
  1115. end;
  1116.  
  1117. { This procedure handles pressing of F7 for CCFileManagerForm }
  1118. procedure TIoManager.OnF7Pressed(Sender: TObject; var Key: Word;
  1119.   Shift: TShiftState);
  1120. begin
  1121.   TCCFileMgrForm( Parent ).BitBtn9Click( Sender );
  1122. end;
  1123.  
  1124. { This procedure handles pressing of F8 for CCFileManagerForm }
  1125. procedure TIoManager.OnF8Pressed(Sender: TObject; var Key: Word;
  1126.   Shift: TShiftState);
  1127. begin
  1128.   TCCFileMgrForm( Parent ).BitBtn6Click( Sender );
  1129. end;
  1130.  
  1131. { This procedure handles pressing of F9 for CCFileManagerForm }
  1132. procedure TIoManager.OnF9Pressed(Sender: TObject; var Key: Word;
  1133.   Shift: TShiftState);
  1134. begin
  1135.   TCCFileMgrForm( Parent ).BitBtn11Click( Sender );
  1136. end;
  1137.  
  1138. { This procedure handles pressing of F10 for CCFileManagerForm }
  1139. procedure TIoManager.OnF10Pressed(Sender: TObject; var Key: Word;
  1140.   Shift: TShiftState);
  1141. begin
  1142.   TCCFileMgrForm( Parent ).BitBtn7Click( Sender );
  1143. end;
  1144.  
  1145. { This procedure handles pressing of F11 for CCFileManagerForm }
  1146. procedure TIoManager.OnF11Pressed(Sender: TObject; var Key: Word;
  1147.   Shift: TShiftState);
  1148. begin
  1149.   TCCFileMgrForm( Parent ).BitBtn8Click( Sender );
  1150. end;
  1151.  
  1152. { This procedure handles pressing of F12 for CCFileManagerForm }
  1153. procedure TIoManager.OnF12Pressed(Sender: TObject; var Key: Word;
  1154.   Shift: TShiftState);
  1155. begin
  1156.   TCCFileMgrForm( Parent ).BitBtn10Click( Sender );
  1157. end;
  1158.  
  1159. { Returns True if the Left Button was pressed in the last mouse operation }
  1160. function TIOManager.WasLeftPressed : Boolean;
  1161. begin
  1162.   if ( mbLeft = WhichButton ) then WasLeftPressed := true else
  1163.    WasLeftPressed := false;
  1164. end;
  1165.  
  1166. { Returns true if the Right Button was pressed in the last mouse operation }
  1167. function TIOManager.WasRightPressed : Boolean;
  1168. begin
  1169.   if mbRight = WhichButton then WasRightPressed := true else
  1170.    WasRightPressed := false;
  1171. end;
  1172.  
  1173. { Returns true if the Middle Button was pressed in the last mouse operation }
  1174. function TIOManager.WasMiddlePressed : Boolean;
  1175. begin
  1176.   if mbMiddle = WhichButton then WasMiddlePressed := true else
  1177.    WasMiddlePressed := false;
  1178. end;
  1179.  
  1180. { Returns true if the ALT key was down during the last IO operation }
  1181. function TIOManager.WasALTPressed : Boolean;
  1182. begin
  1183.   if ssAlt in WhichState then WasALTPressed := true else
  1184.    WasALTPressed := false;
  1185. end;
  1186.  
  1187. { Returns true if either SHIFT key was down during the last IO operation }
  1188. function TIOManager.WasSHIFTPressed : Boolean;
  1189. begin
  1190.   if ssShift in WhichState then WasSHIFTPressed := true else
  1191.    WasSHIFTPressed := false;
  1192. end;
  1193.  
  1194. { Returns true if the Control Key was down during the last IO operation }
  1195. function TIOManager.WasCTRLPressed : Boolean;
  1196. begin
  1197.   if ssCtrl in WhichState then WasCTRLPressed := true else
  1198.    WasCTRLPressed := false;
  1199. end;
  1200.  
  1201.  
  1202. { This procedure does a fully error-trapped change directory }
  1203. procedure TFileWorkBench.ChangeTheDirectory( NewPath : String );
  1204. var CurrentDirectory : String;
  1205. begin
  1206.   if NewPath = '..' then
  1207.   begin { Back up one level }
  1208.     {$I+}
  1209.     try
  1210.       { Find the current directory }
  1211.       GetDir( 0 , CurrentDirectory );
  1212.       { Use EFP to move up one level }
  1213.       CurrentDirectory := ExtractFilePath( CurrentDirectory );
  1214.       { Strip trailing \ if not root }
  1215.       CurrentDirectory := StripNonRootTrailingBackSlash( CurrentDirectory );
  1216.       { Try the change to the New drive }
  1217.       ChDir( CurrentDirectory );
  1218.     except
  1219.       { if any exception occurs instantiate exception and show }
  1220.       On E:EInOutError do
  1221.       begin
  1222.         { Call custom error display/lookup procedure }
  1223.         HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  1224.          E.Message , E.ErrorCode );
  1225.       end;
  1226.     end;
  1227.   end
  1228.   else
  1229.   begin { Change to explicit path }
  1230.     {$I+}
  1231.     try
  1232.       { Get target directory path }
  1233.       CurrentDirectory := NewPath;
  1234.       { Strip trailing \ if not root }
  1235.       CurrentDirectory := StripNonRootTrailingBackSlash( CurrentDirectory );
  1236.       { Try the change to the New drive }
  1237.       ChDir( CurrentDirectory );
  1238.     except
  1239.       { if any exception occurs instantiate exception and show }
  1240.       On E:EInOutError do
  1241.       begin
  1242.         { Call custom error display/lookup procedure }
  1243.         HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  1244.          E.Message , E.ErrorCode );
  1245.       end;
  1246.     end;
  1247.   end;
  1248. end;
  1249.  
  1250. { This procedure does a fully error-trapped change directory }
  1251. procedure TFileWorkBench.ChangeTheDriveAndDirectory( NewDrive : Integer );
  1252. var CurrentDirectory : String;
  1253. begin
  1254.   {$I+}
  1255.   try
  1256.     { Find the working directory on New drive }
  1257.     GetDir( NewDrive , CurrentDirectory );
  1258.     { Try the change to the New drive }
  1259.     ChDir( CurrentDirectory );
  1260.   except
  1261.     { if any exception occurs instantiate exception and show }
  1262.     On E:EInOutError do
  1263.     begin
  1264.       { Call custom error display/lookup procedure }
  1265.       HandleIOException( EOC_CHANGEDIR , CurrentDirectory ,
  1266.        E.Message , E.ErrorCode );
  1267.     end;
  1268.   end;
  1269. end;
  1270.  
  1271. { This procedure copies a single file with error trapping }
  1272. procedure TFileWorkBench.CopyTheFile( OldPath , NewPath : String );
  1273. var AResult : Boolean; { Internal data flag }
  1274. begin
  1275.   { If Copyfile returns false an error occurred }
  1276.   AResult := CopyFile( OldPath , NewPath +
  1277.    ExtractFileName( OldPath ));
  1278.   { Display meaningful error message }
  1279.   if not AResult then HandleDOSError( GlobalErrorType , OldPath, GlobalError );
  1280. end;
  1281.  
  1282. { This procedure moves a file by copying and delete it }
  1283. procedure TFileWorkBench.MoveTheFile( OldPath , NewPath : String );
  1284. var AResult : Boolean; { Internal data flag }
  1285.     TheFile : File;    { Use to get errors  }
  1286. begin
  1287.   { If Copyfile returns false an error occurred }
  1288.   AResult := CopyFile( OldPath , NewPath +
  1289.     ExtractFileName( OldPath ));
  1290.   { Display meaningful error message }
  1291.   if not AResult then HandleDOSError( GlobalErrorType ,
  1292.     OldPath , GlobalError );
  1293.   { After valid copying, delete source file }
  1294.   {$I+}
  1295.   if AResult then try
  1296.     { Use this trick to get valid exception handling }
  1297.     AssignFile( TheFile , OldPath );
  1298.     { Use erase because Deletefile doesn't give exceptions! }
  1299.     Erase( TheFile );
  1300.   except
  1301.     { if any exception occurs instantiate exception and show }
  1302.     On E:EInOutError do
  1303.     begin
  1304.       { Call custom error display/lookup procedure }
  1305.       HandleIOException( EOC_DELETEFILE , OldPath ,
  1306.        E.Message , E.ErrorCode );
  1307.     end;
  1308.   end;
  1309. end;
  1310.  
  1311. { This procedure safely deletes a single file }
  1312. procedure TFileWorkBench.DeleteTheFile( ThePath : String );
  1313. var TheFile : File; { Internal file handle }
  1314. begin
  1315.   {$I+}
  1316.   try
  1317.     { Use this trick to get valid exception handling }
  1318.     AssignFile( TheFile , ThePath );
  1319.     { Use erase because Deletefile doesn't give exceptions! }
  1320.     Erase( TheFile );
  1321.   except
  1322.     { if any exception occurs instantiate exception and show }
  1323.     On E:EInOutError do
  1324.     begin
  1325.       { Call custom error display/lookup procedure }
  1326.       HandleIOException( EOC_DELETEFILE , ThePath ,
  1327.        E.Message , E.ErrorCode );
  1328.     end;
  1329.   end;
  1330. end;
  1331.  
  1332. { This procedure renames a file with full error trapping }
  1333. procedure TFileWorkBench.RenameTheFile( OldPath , NewName : String );
  1334. var TheFile : File; { Internal file handle }
  1335. begin
  1336.   {$I+}
  1337.   try
  1338.     { Use this trick to get valid exception handling }
  1339.     AssignFile( TheFile , OldPath );
  1340.     { Use this because RenameFile doesn't give exceptions! }
  1341.     Rename( TheFile , NewName );
  1342.   except
  1343.     { if any exception occurs instantiate exception and show }
  1344.     On E:EInOutError do
  1345.     begin
  1346.       { Call custom error display/lookup procedure }
  1347.       HandleIOException( EOC_RENAMEFILE , OldPath  ,
  1348.        E.Message , E.ErrorCode );
  1349.     end;
  1350.   end;
  1351. end;
  1352.  
  1353. { This procedure creates a New directory with full error trapping }
  1354. procedure TFileWorkBench.CreateNewDirectory( NewPath : String );
  1355. begin
  1356.   {$I+}
  1357.   try
  1358.     Mkdir( NewPath );
  1359.   except
  1360.     { if any exception occurs instantiate exception and show }
  1361.     On E:EInOutError do
  1362.     begin
  1363.       { Call custom error display/lookup procedure }
  1364.       HandleIOException( EOC_MAKEDIR , NewPath  ,
  1365.        E.Message , E.ErrorCode );
  1366.     end;
  1367.   end;
  1368. end;
  1369.  
  1370. { This procedure remove a directory with full error trapping }
  1371. procedure TFileWorkBench.RemoveDirectory( ThePath : String );
  1372. begin
  1373.   {$I+}
  1374.   try
  1375.     Rmdir( ThePath );
  1376.   except
  1377.     { if any exception occurs instantiate exception and show }
  1378.     On E:EInOutError do
  1379.     begin
  1380.       { Call custom error display/lookup procedure }
  1381.       HandleIOException( EOC_DELETEDIR , ThePath  ,
  1382.        E.Message , E.ErrorCode );
  1383.     end;
  1384.   end;
  1385. end;
  1386.  
  1387. { Use this to set the attributes of a file with error trapping }
  1388. procedure TFileWorkBench.SetFileAttributes( TheFile  : String;
  1389.            TheAttributes : Integer );
  1390. var TheResult : Integer; { Holds error code if any }
  1391. begin
  1392.   { Attempt to set the attributes }
  1393.   TheResult := FileSetAttr( TheFile , TheAttributes );
  1394.   { if negative number error, so signal }
  1395.   if TheResult < 0 then
  1396.    HandleDOSError( EOC_SETATTR , TheFile , -TheResult );
  1397. end;
  1398.  
  1399. { This procedure recursively copies a directory to a New path }
  1400. procedure TFileWorkBench.RecursivelyCopyDirectory( OldPath , NewPath : String );
  1401. var TheDir : String; { Holds source directory }
  1402. begin
  1403.   { Get the source directory to copy }
  1404.   TheDir := ExtractFileName( OldPath );
  1405.   { Force a backslash to the Newpath variable }
  1406.   NewPath := ForceTrailingBackSlash( NewPath );
  1407.   { Add the source directory to the target path }
  1408.   NewPath := NewPath + TheDir;
  1409.   { Create a New directory with the New name }
  1410.   CreateNewDirectory( NewPath );
  1411.   { Force a backslash for compatibility }
  1412.   NewPath := FOrcetrailingBackSlash( NewPath );
  1413.   { Do the recursive call }
  1414.   HandleRecursiveAction( OldPath , NewPath , FAC_COPY );
  1415. end;
  1416.  
  1417. { This procedure recursively moves a directory tree }
  1418. procedure TFileWorkBench.RecursivelyMoveDirectory( OldPath , NewPath : String );
  1419. var TheDir    : String; { Holds source directory  }
  1420.     SavedPath : String; { Holds saved dir to kill }
  1421. begin
  1422.   { Get the source directory to move }
  1423.   TheDir := ExtractFileName( OldPath );
  1424.   { Force a backslash to the Newpath variable }
  1425.   NewPath := ForceTrailingBackSlash( NewPath );
  1426.   { Save the starting path just in case }
  1427.   SavedPath := OldPath;
  1428.   { Add the source directory to the target path }
  1429.   NewPath := NewPath + TheDir;
  1430.   { Create a New directory with the New name }
  1431.   CreateNewDirectory( NewPath );
  1432.   { Force a backslash for compatibility }
  1433.   NewPath := FOrcetrailingBackSlash( NewPath );
  1434.   { Do the recursive call }
  1435.   HandleRecursiveAction( OldPath , NewPath , FAC_MOVE );
  1436.   { Remove the source directory }
  1437.   RemoveDirectory( SavedPath );
  1438. end;
  1439.  
  1440. { This procedure handles recursively deleting an entire directory tree }
  1441. procedure TFileWorkBench.RecursivelyDeleteDirectory( ThePath : String );
  1442. begin
  1443.   HandleRecursiveAction( ThePath , '' , FAC_DELETE );
  1444. end;
  1445.  
  1446.  
  1447. { This is the generic routine to copy, move, and delete whole directory trees }
  1448. procedure TFileWorkBench.HandleRecursiveAction( StartingPath , NewPath : String;
  1449.            ActionCode : Integer );
  1450. { VITAL!!! These variables MUST be local for recursrion to work! }
  1451. var
  1452.     Finished        : Boolean;         { Loop flag              }
  1453.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  1454.     TheResult       : Integer;         { return variable        }
  1455.     TargetPath ,
  1456.     FileMask   ,
  1457.     TheWorkingDirectory ,
  1458.     TheStoredWorkingDirectory ,
  1459.     ModifiedDirectory  : String;       { path for FF/FN         }
  1460.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  1461.     ButtonColor   ,                    { main panel color       }
  1462.     ButtonHLColor ,                    { bright panel color     }
  1463.     ButtonSColor  ,                    { dark panel color       }
  1464.     Textcolor       : TColor;          { label text color       }
  1465.     TheFile         : File;
  1466.  
  1467. begin
  1468.   { Set up the initial variables }
  1469.   Finished := false;
  1470.   TheWorkingDirectory := StartingPath;
  1471.   TheStoredWorkingDirectory := TheWorkingDirectory;
  1472.   TheWorkingDirectory := TheWorkingDirectory + '\*.*';
  1473.   TargetPath := ExtractFilePath( TheWorkingDirectory );
  1474.   { Make the call to FindFirst set to get any file }
  1475.   TheResult := FindFirst( TheWorkingDirectory , faAnyFile , TheSR );
  1476.   { loop through all files in the directory and delete them }
  1477.   while not Finished do
  1478.   begin
  1479.     { Make call to FindNext, using only SearchRecord from FindFirst }
  1480.     TheResult := FindNext( TheSR );
  1481.     { A -1 result means no more files so exit }
  1482.     if TheResult < 0 then finished := true else
  1483.     begin
  1484.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory )
  1485.        <> faDirectory ) then
  1486.       begin { A File }
  1487.         case ActionCode of
  1488.           FAC_COPY :
  1489.               begin
  1490.                 CopyTheFile( TargetPath + TheSR.Name , NewPath );
  1491.               end;
  1492.           FAC_MOVE :
  1493.               begin
  1494.                 MoveTheFile( TargetPath + TheSR.Name , NewPath );
  1495.               end;
  1496.           FAC_DELETE :
  1497.               begin { Delete }
  1498.                 if MessageDlg( 'Delete file ' + TargetPath + TheSR.Name + '?',
  1499.                    mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1500.                     DeleteTheFile( TargetPath + TheSR.Name );
  1501.               end;
  1502.         end;
  1503.       end;
  1504.     end;
  1505.   end;
  1506.   { Call FindClose for Windows NT/Windows 95 compatibility }
  1507.   FindClose( TheSR );
  1508.   { Set up the variables to do recursive calls on all directories}
  1509.   Finished := false;
  1510.   ModifiedDirectory := TheStoredWorkingdirectory + '\*.*';
  1511.   { Make the call to FindFirst set to get any file, ignore result }
  1512.   TheResult := FindFirst( ModifiedDirectory , faDirectory , TheSR );
  1513.   while not Finished do
  1514.   begin
  1515.     { Make call to FindNext, using only SearchRecord from FindFirst }
  1516.     TheResult := FindNext( TheSR );
  1517.     { A -1 result means no more files so exit }
  1518.     if TheResult < 0 then
  1519.       finished := true
  1520.     else
  1521.     begin
  1522.       if TheSR.Name <> '..' then { Ignore backup in this case }
  1523.       begin
  1524.         if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory )
  1525.          = faDirectory ) then
  1526.         begin
  1527.           { Send in the New directory name }
  1528.           ModifiedDirectory := TheStoredWorkingDirectory  + '\' +
  1529.            TheSR.Name;
  1530.           { Reproduce directory structure for recursion in copy/move }
  1531.           NewPath := NewPath + TheSR.Name;
  1532.           case ActionCode of
  1533.             FAC_COPY , FAC_MOVE :
  1534.                begin { Create ahead for move and copy }
  1535.                  { Make the New directory for moving and copying }
  1536.                  CreateNewDirectory( NewPath );
  1537.                  { Force a backslash for compatibility }
  1538.                  NewPath := ForceTrailingBackSlash( NewPath );
  1539.                end;
  1540.             FAC_DELETE :
  1541.                begin  { No prior action needed for Delete }
  1542.                end;
  1543.           end;
  1544.           { Do the recursive call }
  1545.           HandleRecursiveAction( ModifiedDirectory , NewPath , ActionCode );
  1546.           case ActionCode of
  1547.             FAC_COPY :
  1548.                begin { no action for copy }
  1549.                end;
  1550.             FAC_MOVE , FAC_DELETE :
  1551.                begin  { Delete }
  1552.                  { Get a confirmation }
  1553.                  if MessageDlg( 'Remove Directory ' + TargetPath + TheSR.Name
  1554.                   + '?', mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  1555.                    RemoveDirectory( TargetPath + TheSR.Name );
  1556.                end;
  1557.           end;
  1558.         end;
  1559.       end;
  1560.     end;
  1561.   end;
  1562. end;
  1563.  
  1564. { This is a generic copy routine taken from Delphi sample code }
  1565. { This function calls the sample Copy code and handles errors }
  1566. function TFileWorkBench.CopyFile( TargetPath ,
  1567.           DestinationPath : String ) : Boolean;
  1568. begin
  1569.   { Set global error value to no error }
  1570.   GlobalError := 0;
  1571.   { Call the sample procedure to do the copy }
  1572.   FMXUCopyFile( TargetPath, DestinationPath , GlobalErrorType , GlobalError );
  1573.   { If no error return true else return false }
  1574.   if GlobalError < 0 then CopyFile := false else
  1575.    CopyFile := true;
  1576. end;
  1577.  
  1578. { This procedure handles displaying a user-friendly Dialog box with a }
  1579. { Message for Delphi IO exception errors.                             }
  1580. procedure TFileWorkBench.HandleIOException( TheOpCode : Integer;
  1581.            ThePath : String; TheMessage : String; TheCode : Integer );
  1582. var ErrorMessageString : String;  { Holds internal data }
  1583.     OperationString    : String;  { Holds internal data }
  1584. begin
  1585.   { clear to check for unrecognized code }
  1586.   ErrorMessageString := '';
  1587.   { Check against imported code }
  1588.   case TheCode of
  1589.     2    : ErrorMessageString := 'File not found';
  1590.     3    : ErrorMessageString := 'Path not found';
  1591.     4    : ErrorMessageString := 'Too many open files';
  1592.     5    : ErrorMessageString := 'File access denied';
  1593.     6    : ErrorMessageString := 'Invalid file handle';
  1594.     12    : ErrorMessageString := 'Invalid file access code';
  1595.     15    : ErrorMessageString := 'Invalid drive number';
  1596.     16  : ErrorMessageString := 'Cannot remove current directory';
  1597.     17    : ErrorMessageString := 'Cannot rename across drives';
  1598.     100    : ErrorMessageString := 'Disk read error';
  1599.     101    : ErrorMessageString := 'Disk write error';
  1600.     102    : ErrorMessageString := 'File not assigned';
  1601.     103    : ErrorMessageString := 'File not open';
  1602.     104    : ErrorMessageString := 'File not open for input';
  1603.     105    : ErrorMessageString := 'File not open for output';
  1604.   end;
  1605.   case TheOpCode of
  1606.     EOC_CHANGEDIR : OperationString := 'Unable to Change Directory due to ';
  1607.     EOC_SOURCECOPY : OperationString := 'Unable to Copy due to Source File ';
  1608.     EOC_DESTCOPY : OperationString := 'Unable to Copy due to Destination File ';
  1609.     EOC_DELETEFILE : OperationString := 'Unable to Delete File due to ';
  1610.     EOC_DELETEDIR : OperationString := 'Unable to Delete Directory due to ';
  1611.     EOC_RENAMEFILE : OperationString := 'Unable to Rename File due to ';
  1612.     EOC_MAKEDIR : OperationString := 'Unable to Create New Directory due to ';
  1613.     EOC_SETATTR : OperationString := 'Unable to Set File Attributes due to ';
  1614.   end;
  1615.   { If not recognized use message; not a DOS error; reset cursor for neatness }
  1616.   if ErrorMessageString = '' then
  1617.   begin
  1618.     Screen.Cursor := crDefault;
  1619.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  1620.      TheMessage , mtError , [mbOK],0);
  1621.   end
  1622.   else
  1623.   begin
  1624.     { Recognized DOS exception, reset cursor for neatness }
  1625.     Screen.Cursor := crDefault;
  1626.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  1627.      ErrorMessageString , mtError , [mbOK], 0 );
  1628.   end;
  1629. end;
  1630.  
  1631. { This procedure handles displaying a user-friendly Dialog box with a }
  1632. { Message for DOS error codes.                                        }
  1633. procedure TFileWorkBench.HandleDOSError( TheOpCode : Integer;
  1634.            ThePath : String;  TheCode : Integer );
  1635. var ErrorMessageString : String;  { internal message holder }
  1636.     OperationString : String;     { internal message holder }
  1637. begin
  1638.   { clear the message holder to check for unrecognized code }
  1639.   ErrorMessageString := '';
  1640.   { Negate the code back to normal number and check to set string }
  1641.   case -TheCode of
  1642.     2    : ErrorMessageString := 'File not found';
  1643.     3    : ErrorMessageString := 'Path not found';
  1644.     4    : ErrorMessageString := 'Too many open files';
  1645.     5    : ErrorMessageString := 'File access denied';
  1646.     6    : ErrorMessageString := 'Invalid file handle';
  1647.     12    : ErrorMessageString := 'Invalid file access code';
  1648.     15    : ErrorMessageString := 'Invalid drive number';
  1649.     16  : ErrorMessageString := 'Cannot remove current directory';
  1650.     17    : ErrorMessageString := 'Cannot rename across drives';
  1651.     100    : ErrorMessageString := 'Disk read error';
  1652.     101    : ErrorMessageString := 'Disk write error';
  1653.     102    : ErrorMessageString := 'File not assigned';
  1654.     103    : ErrorMessageString := 'File not open';
  1655.     104    : ErrorMessageString := 'File not open for input';
  1656.     105    : ErrorMessageString := 'File not open for output';
  1657.     157 : ErrormessageString := 'Could not open Source File';
  1658.     159 : ErrormessageString := 'Could not open Target File';
  1659.   end;
  1660.   case TheOpCode of
  1661.     EOC_CHANGEDIR : OperationString := 'Unable to Change Directory due to ';
  1662.     EOC_SOURCECOPY : OperationString := 'Unable to Copy due to Source File ';
  1663.     EOC_DESTCOPY : OperationString := 'Unable to Copy due to Destination File ';
  1664.     EOC_DELETEFILE : OperationString := 'Unable to Delete File due to ';
  1665.     EOC_DELETEDIR : OperationString := 'Unable to Delete Directory due to ';
  1666.     EOC_RENAMEFILE : OperationString := 'Unable to Rename File due to ';
  1667.     EOC_MAKEDIR : OperationString := 'Unable to Create New Directory due to ';
  1668.     EOC_SETATTR : OperationString := 'Unable to Set File Attributes due to ';
  1669.   end;
  1670.   { If the string is empty an unrecognized code was sent in }
  1671.   if ErrorMessageString = '' then
  1672.   begin
  1673.     { Sent up db based on source or target error; reset cursor for neatness }
  1674.     Screen.Cursor := crDefault;
  1675.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' Error Code: ' +
  1676.      IntToStr( TheCode ) , mtError , [mbOK],0);
  1677.   end
  1678.   else  { Code is recognized, use message from case statement }
  1679.   begin
  1680.     { Format the output for source or target error }
  1681.     Screen.Cursor := crDefault;
  1682.     MessageDlg( OperationString + ExtractFileName( ThePath ) + ' ' +
  1683.      ErrorMessageString , mtError , [mbOK], 0 );
  1684.   end;
  1685. end;
  1686.  
  1687. { This procedure sets the imported booleans to the file's attributes }
  1688. procedure TFileWorkBench.GetFileAttributes( TheFile : String; var IsDirectory ,
  1689.            IsArchive , IsVolumeID , IsHidden , IsReadOnly ,
  1690.             IsSysFile : Boolean );
  1691. var TheResult : Integer; { Traps for error code on VolumeID }
  1692. begin
  1693.   { Clear the imported flags for default }
  1694.   IsDirectory := false;
  1695.   IsArchive := false;
  1696.   IsVolumeID := false;
  1697.   IsHidden := False;
  1698.   IsReadOnly := false;
  1699.   IsSysFile := false;
  1700.   { Make the Dos call }
  1701.   TheResult := FileGetAttr( TheFile );
  1702.   if TheResult < 0 then
  1703.   begin
  1704.     { Volume ID returns -2 (?) }
  1705.     IsVolumeID := true;
  1706.     { It has no other properties }
  1707.     exit;
  1708.   end;
  1709.   { Use AND test to set all other properties }
  1710.   if (( TheResult and faDirectory ) = faDirectory ) then IsDirectory := true;
  1711.   if (( TheResult and faArchive ) = faArchive ) then IsArchive := true;
  1712.   if (( TheResult and faVolumeID ) = faVolumeID ) then IsVolumeID := true;
  1713.   if (( TheResult and faReadOnly ) = faReadOnly ) then IsReadOnly := true;
  1714.   if (( TheResult and faHidden ) = faHidden ) then IsHidden := true;
  1715.   if (( TheResult and faSysFile ) = faSysFile ) then IsSysFile := true;
  1716. end;
  1717.  
  1718. { This function makes sure a pathname has a trailing \ }
  1719. function TFileWorkBench.ForceTrailingBackSlash(
  1720.           const TheFileName : String ) : String;
  1721. var TempString : String;  { Used to hold function result }
  1722. begin
  1723.   { If no trailing \ add one (root will already have one.) }
  1724.   if TheFileName[ Length( TheFileName ) ] <> '\' then
  1725.    TempString := TheFileName + '\' else TempString := TheFileName;
  1726.   { Return modified or non-modified string }
  1727.   ForceTrailingBackslash := TempString;
  1728. end;
  1729.  
  1730. { This function makes sure a non-root dir has no trailing \ }
  1731. function TFileWorkBench.StripNonRootTrailingBackSlash(
  1732.           const TheFileName : String ) : String;
  1733. var TempString : String ; { Used to hold function result }
  1734. begin
  1735.   { Default is no change }
  1736.   TempString := TheFileName;
  1737.   { If not root then }
  1738.   if Length( TheFileName ) > 3 then
  1739.   begin
  1740.     { If has a trailing backslash remove it }
  1741.     if TheFileName[ Length( TheFileName )] = '\' then
  1742.     begin
  1743.       TempString := Copy( TheFileName , 1 ,
  1744.        Length( TheFileName ) - 1 );
  1745.     end;
  1746.   end;
  1747.   { Export the final result }
  1748.   StripNonRootTrailingBackSlash := TempString;
  1749. end;
  1750.  
  1751. { This gets the next selected listbox item }
  1752. function TIconFileListBox.GetNextSelection( SourceDirectory : String;
  1753.           var CurrentItem : Integer ): String;
  1754. var TheResult : String;  { Internal storage }
  1755.     finished  : boolean; { Loop flag        }
  1756. begin
  1757.   { If out of items to check signal and exit }
  1758.   if CurrentItem > Items.Count then TheResult := '' else
  1759.   begin
  1760.     { Otherwise scan from current position till match or end }
  1761.     finished := false;
  1762.     while not finished do
  1763.     begin
  1764.       { Check against selected property }
  1765.       if Selected[ CurrentItem - 1 ] then
  1766.       begin
  1767.         { If selected then return it and abort loop }
  1768.         TheResult := SourceDirectory + Items[ CurrentItem - 1 ];
  1769.         finished := true;
  1770.         { Increment current position }
  1771.         CurrentItem := CurrentItem + 1;
  1772.      end
  1773.       else
  1774.       begin
  1775.         { Increment current position }
  1776.         CurrentItem := CurrentItem + 1;
  1777.         { Otherwise check for end of data and abort if out of entries }
  1778.         if CurrentItem > Items.Count then
  1779.         begin
  1780.           TheResult := '';
  1781.           finished := true;
  1782.         end;
  1783.       end;
  1784.     end;
  1785.   end;
  1786.   { Return stored result }
  1787.   GetNextSelection := TheResult;
  1788. end;
  1789.  
  1790. { Modified from VCL Source Copyright 1995 }
  1791. { Borland International, Inc.             }
  1792. { Use this to override display with icons }
  1793. procedure TIconFileListBox.ReadFileNames;
  1794. var
  1795.   AttrIndex   : TFileAttr;
  1796.   i           : Integer;
  1797.   FileExt     : string;
  1798.   MaskPtr     : PChar;
  1799.   Ptr         : PChar;
  1800.   AttrWord    : Word;
  1801.   TempPicture : TPicture;
  1802.   TempBmp     : TBitmap;
  1803.   TempIcon    : TIcon;
  1804. const
  1805.   Attributes: array[TFileAttr] of Word =
  1806.   ( DDL_READONLY , DDL_HIDDEN , DDL_SYSTEM , $0008 , DDL_DIRECTORY ,
  1807.     DDL_ARCHIVE  , DDL_EXCLUSIVE );
  1808. begin
  1809.   { if no handle allocated yet, this call will force         }
  1810.   { one to be allocated incorrectly (i.e. at the wrong time. }
  1811.   { In due time, one will be allocated appropriately.        }
  1812.   AttrWord := DDL_READWRITE;
  1813.   if HandleAllocated then
  1814.   begin
  1815.     { Set attribute flags based on values in FileType }
  1816.     for AttrIndex := ftReadOnly to ftArchive do
  1817.      if AttrIndex in FileType then
  1818.       AttrWord := AttrWord or Attributes[ AttrIndex ];
  1819.  
  1820.     { Use Exclusive bit to exclude normal files }
  1821.     if not ( ftNormal in FileType ) then
  1822.       AttrWord := AttrWord or DDL_EXCLUSIVE;
  1823.  
  1824.     ChDir( FDirectory ); { go to the directory we want }
  1825.     Clear;               { clear the list }
  1826.  
  1827.     MaskPtr := FMask;
  1828.     while MaskPtr <> nil do
  1829.     begin
  1830.       Ptr := StrScan ( MaskPtr , ';' );
  1831.       if Ptr <> nil then  Ptr^ := #0;
  1832.       { build the list }
  1833.       SendMessage( Handle , LB_DIR , AttrWord , Longint( MaskPtr ));
  1834.       if Ptr <> nil then
  1835.       begin
  1836.         Ptr^ := ';';
  1837.         Inc ( Ptr );
  1838.       end;
  1839.       MaskPtr := Ptr;
  1840.     end;
  1841.     { Now add the bitmaps }
  1842.     {---------------------------- begin custom code --------------------------}
  1843.     { Create the TPicture for exchange purposes }
  1844.     TempPicture := TPicture.Create;
  1845.     { Set it to icon widths }
  1846.     TempPicture.Bitmap.Width := 32;
  1847.     TempPicture.Bitmap.Height := 32;
  1848.     { Run down the list }
  1849.     for i := 0 to Items.Count - 1 do
  1850.     begin
  1851.       { Create a New temporary icon }
  1852.       TempIcon := TIcon.Create;
  1853.       { Call the custom DRWS routine to get icon for a file }
  1854.       GetIconForFile( Items[ i ] , TempIcon );
  1855.       { Put the icon on the bitmap for the picture via draw }
  1856.       { Note 1 , 1 due to bug in Draw?                      }
  1857.       TempPicture.Bitmap.Canvas.Draw( 1 , 1 , TempIcon );
  1858.       { Create a temporary bitmap }
  1859.       TempBmp := TBitmap.Create;
  1860.       { Set its width to those of the previous object's bitmaps }
  1861.       TempBmp.Width := 16;
  1862.       TempBmp.Height := 15;
  1863.       { Resize the icon's bitmap to the smaller size with stretchdraw }
  1864.       TempBmp.Canvas.StretchDraw( Rect( 1 , 1 , 15 , 14 ) ,
  1865.        TempPicture.Bitmap );
  1866.       { Set the Objects list to the bitmap }
  1867.       Items.Objects[ i ] := TempBmp;
  1868.       { Free the icon each iteration; don't free the TempBmp as list does }
  1869.       TempIcon.Free;
  1870.     end;
  1871.     { Free the TPicture exchange element }
  1872.     TempPicture.Free;
  1873.     {------------------------ end custom code --------------------------------}
  1874.     Change;
  1875.   end;
  1876. end;
  1877.  
  1878. { Use this to respond to dbl-clicking FLB filename }
  1879. procedure TIconFileListBox.TheDblClick(Sender: TObject);
  1880. begin
  1881.   { Call shellexec as a wrapper around ShellExecute API call }
  1882.   { False indicates failure, signal error                    }
  1883.   if not ShellExec( ExpandFileName( Items[ ItemIndex ] ), '' , '', false ,
  1884.    SW_SHOWNORMAL , false ) then MessageDlg('Could not Shell out to ' +
  1885.     Items[ ItemIndex ] , mtError, [mbOK], 0);
  1886. end;
  1887.  
  1888. { Create method for FIP                                }
  1889. constructor TIconFileListBox.Create( AOwner : TComponent );
  1890. begin
  1891.   { call inherited -- VITAL! }
  1892.   inherited Create( AOwner );
  1893.   { set the mouse method }
  1894.   OnDblClick := TheDblClick;
  1895. end;
  1896.  
  1897. { Create method for FIP                                }
  1898. constructor TFileIconPanel.Create( AOwner : TComponent );
  1899. begin
  1900.   { call inherited -- VITAL! }
  1901.   inherited Create( AOwner );
  1902.   { create icon and label components, making self owner/displayer }
  1903.   FTheIcon := TIcon.Create;
  1904.   FTheLabel := TLabel.Create( Self );
  1905.   FThelabel.Parent := Self;
  1906.   { Set own and labels mouse methods to stored methods }
  1907.   OnMouseUp := TheMouseUp;
  1908.   OnMouseDown := TheMouseDown;
  1909.   OnMouseMove := TheMouseMove;
  1910.   OnDragOver := TheDragOver;
  1911.   OnDragDrop := TheDragDrop;
  1912.   { Set alignment and autosize properties of the label }
  1913.   FTheLabel.Autosize := false;
  1914.   FTheLabel.Alignment := taCenter;
  1915.   { Set selected to false }
  1916.   Selected := false;
  1917. end;
  1918.  
  1919. procedure TFileIconPanel.WMLButtonDblClk(var Message: TWMLButtonDblClk);
  1920. var CurrentDirectory : String;    { Use to store dirs }
  1921.     TheDrive         : String;    { Get drive letter  }
  1922.     WhichDrive       : Integer;   { Get drive number  }
  1923.     ErrorCheck       : Integer;
  1924.     TheFWB           : TFileWorkBench;
  1925. begin
  1926.   { Create FileWorkBench for later use }
  1927.   TheFWB := TFileWorkBench.Create( Self );
  1928.   { Check for label or FIP sender }
  1929.   if FTheLabel.Caption = '..' then
  1930.   begin { deal with backup request }
  1931.     { Change to New directory }
  1932.     TheFWB.ChangeTheDirectory( '..' );
  1933.     { Call special method due to SendMessage problem! }
  1934.     TFileIconPanelScrollBox( Parent ).Update;
  1935.   end
  1936.   else
  1937.   begin
  1938.     { Check for DRIVE id in name }
  1939.     if Pos( 'DRIVE' , FTheName ) <> 0 then
  1940.     begin { Double Click on a Drive Icon }
  1941.       { Pull out the letter from name }
  1942.       TheDrive := Copy( FtheName , 7 , 1 );
  1943.       { Convert it to a number }
  1944.       WhichDrive := ( Ord( TheDrive[ 1 ] ) - Ord( 'A' )) + 1;
  1945.       TheFWB.ChangeTheDriveAndDirectory( WhichDrive );
  1946.       { Call special method due to SendMessage problem! }
  1947.       TFileIconPanelScrollBox( Parent ).Update;
  1948.     end
  1949.     else
  1950.     begin { Double click on a dir/file icon }
  1951.       if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  1952.       begin { A directory, change to it }
  1953.         { Since full path in name, simply change to it! }
  1954.         TheFWB.ChangeTheDirectory( FTheName );
  1955.         { Call special method due to SendMessage problem! }
  1956.         TFileIconPanelScrollBox( Parent ).Update;
  1957.       end
  1958.       else
  1959.       begin { A file; attempt to shellexecute it }
  1960.         { Call shellexec as a wrapper around ShellExecute API call }
  1961.         { False indicates failure, signal error                    }
  1962.         if not ShellExec( FTheName , '' , '', false , SW_SHOWNORMAL , false )
  1963.          then MessageDlg('Could not Shell out to ' + FTheName , mtError,
  1964.           [mbOK], 0);
  1965.       end;
  1966.     end;
  1967.   end;
  1968.   TheFWB.Free; { This prevents resource leak }
  1969. end;
  1970.  
  1971. { Initialization method for FIP                                         }
  1972. procedure TFileIconPanel.Initialize( PanelX              ,
  1973.                                      PanelY              ,
  1974.                                      PanelWidth          ,
  1975.                                      PanelHeight         ,
  1976.                                      PanelBevelWidth     ,
  1977.                                      LabelFontSize         : Integer;
  1978.                                      PanelColor          ,
  1979.                                      PanelHighlightColor ,
  1980.                                      PanelShadowColor    ,
  1981.                                      LabelTextColor        : TColor;
  1982.                                      TheFilename         ,
  1983.                                      LabelFontName         : String;
  1984.                                      LabelFontStyle        : TFontStyles;
  1985.                                      ExtraData             : Integer );
  1986.  
  1987. var TheLabelHeight ,             { Holder for label pixel height }
  1988.     TheLabelWidth    : Integer;  { Holder for label pixel width  }
  1989.     TheOtherPChar    : PChar;    { Windows ASCIIZ string         }
  1990.     HolderBMP        : TBitmap;  { Holds working bitmap for tnail}
  1991.     HoldName         : String;
  1992. begin
  1993.   { Set the basic properties based on imported parameters }
  1994.   Left := PanelX;
  1995.   Top := PanelY;
  1996.   Width := PanelWidth;
  1997.   Height := PanelHeight;
  1998.   Color := PanelColor;
  1999.   BevelWidth := PanelBevelWidth;
  2000.   FHighlightColor := PanelHighlightColor;
  2001.   FShadowColor := PanelShadowColor;
  2002.   FTheName := TheFilename;
  2003.   { If the ExtraData field is non-0 then a drive is being sent in }
  2004.   if ExtraData <> 0 then
  2005.   begin
  2006.     { Use the data field value to determine which icon to get from RES file }
  2007.     case ExtraData of
  2008.       1 : begin
  2009.             GetMem( TheOtherPChar , 255 );
  2010.             StrPCopy( TheOtherPChar , 'FLOPPY35' );
  2011.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  2012.             FreeMem( TheOtherPChar , 255 );
  2013.           end;
  2014.       2 : begin
  2015.             GetMem( TheOtherPChar , 255 );
  2016.             StrPCopy( TheOtherPChar , 'FIXEDHD' );
  2017.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  2018.             FreeMem( TheOtherPChar , 255 );
  2019.           end;
  2020.       3 : begin
  2021.             GetMem( TheOtherPChar , 255 );
  2022.             StrPCopy( TheOtherPChar , 'NETWORKHD' );
  2023.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  2024.             FreeMem( TheOtherPChar , 255 );
  2025.           end;
  2026.       4 : begin
  2027.             GetMem( TheOtherPChar , 255 );
  2028.             StrPCopy( TheOtherPChar , 'CDROM' );
  2029.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  2030.             FreeMem( TheOtherPChar , 255 );
  2031.           end;
  2032.       5 : begin
  2033.             GetMem( TheOtherPChar , 255 );
  2034.             StrPCopy( TheOtherPChar , 'RAM' );
  2035.             FTheIcon.Handle := LoadIcon( hInstance , TheOtherPChar );
  2036.             FreeMem( TheOtherPChar , 255 );
  2037.           end;
  2038.     end;
  2039.     { The FileNme property is already set up for the caption; use directly }
  2040.     FTheLabel.Caption := TheFilename;
  2041.     { Set up the hint for later use (make sure to set ShowHint) }
  2042.     Hint := 'Change to ' + TheFileName;
  2043.     ShowHint := true;
  2044.     { Set up all imported label properties and center it for drawing }
  2045.     with FTheLabel do
  2046.     begin
  2047.       Font.Name := LabelFontName;
  2048.       Font.Size := LabelFontSize;
  2049.       Font.Style := LabelFontStyle;
  2050.       Font.Color := LabelTextColor;
  2051.       Canvas.Brush.Color := PanelColor;
  2052.       Canvas.Font := Font;
  2053.       TheLabelHeight := Canvas.Textheight( Caption ) + 4;
  2054.       TheLabelWidth := Canvas.Textwidth( Caption ) + 4;
  2055.       Left := (( Self.Width - TheLabelWidth ) div 2 ) + 1;
  2056.       Top := ((( Round( Self.Height * 0.25 ) - 6 ) - TheLabelHeight) div 2) + 1;
  2057.       Top := Top + Round( Self.Height * 0.75 );
  2058.       Height := TheLabelHeight;
  2059.       Width := TheLabelWidth;
  2060.     end;
  2061.   end
  2062.   else
  2063.   begin
  2064.     { A file or directory has been sent in; use GetIconForFile to obtain an }
  2065.     { icon either from the file, its owner, or a RES file default.          }
  2066.     GetIconForFile( FTheName , FTheIcon );
  2067.     { Check for the Backup caption and set it specially }
  2068.     if ExtractfileName( FThename ) = '..' then
  2069.     begin
  2070.       FTheLabel.Caption := '..';
  2071.       Hint := 'Up One Level';
  2072.     end
  2073.     else
  2074.     begin
  2075.       if Uppercase( ExtractFileExt( FTheName )) = '.BMP' then
  2076.       begin
  2077.         HoldName := ExtractFileName( FTheName );
  2078.         HoldName := Copy( HoldName, 1 , Length( HoldName ) - 4 );
  2079.         HoldName := HoldName + '.THU';
  2080.         HoldName := ExpandFileName( HoldName );
  2081.         if FileExists( HoldName ) then
  2082.         begin
  2083.           FTheBMP := TBitmap.Create;
  2084.           FTheBMP.LoadFromFile( HoldName );
  2085.         end
  2086.         else
  2087.         begin
  2088.           HolderBMP := TBitmap.Create;
  2089.           HolderBMP.LoadFromFile( FTheName );
  2090.           FTheBMP := CreateBitmapThumbNailFromBitmap( HolderBMP , ThumbNailWidth ,
  2091.            ThumbNailHeight );
  2092.           HolderBMP.Free;
  2093.           FTheBMP.SaveToFile( HoldName );
  2094.         end;
  2095.         FTheLabel.caption := ExtractFileName( UpperCase( FTheName ));
  2096.         Hint := FTheName;
  2097.       end
  2098.       else
  2099.       begin
  2100.         { Otherwise just get the filename for the label caption }
  2101.         { And the full path for the hint (used later.)          }
  2102.         FTheLabel.caption := ExtractFileName( UpperCase( FTheName ));
  2103.         Hint := FTheName;
  2104.       end;
  2105.     end;
  2106.     { Activate showhint so hints are seen }
  2107.     ShowHint := true;
  2108.     { Set label properties with imported values and center for display }
  2109.     with FTheLabel do
  2110.     begin
  2111.       Font.Name := LabelFontName;
  2112.       Font.Size := LabelFontSize;
  2113.       Font.Style := LabelFontStyle;
  2114.       Font.Color := LabelTextColor;
  2115.       Canvas.Brush.Color := PanelColor;
  2116.       Canvas.Font := Font;
  2117.       TheLabelHeight := Canvas.Textheight( Caption ) + 4;
  2118.       TheLabelWidth := Canvas.Textwidth( Caption ) + 4;
  2119.       Left := (( Self.Width - TheLabelWidth ) div 2 ) + 1;
  2120.       Top := ((( Round( Self.Height * 0.25 ) - 6 ) - TheLabelHeight) div 2) + 1;
  2121.       Top := Top + Round( Self.Height * 0.75 );
  2122.       Height := TheLabelHeight;
  2123.       Width := TheLabelWidth;
  2124.     end;
  2125.   end;
  2126. end;
  2127.  
  2128. { Destroy method for FIP }
  2129. destructor TFileIconPanel.Destroy;
  2130. begin
  2131.   { free component resources }
  2132.   if assigned( FTheIcon ) then FTheIcon.Free;
  2133.   FTheLabel.Free;
  2134.   if Assigned( FTheBMP ) then FTheBMP.Free;
  2135.   { call inherited -- VITAL! }
  2136.   inherited Destroy;
  2137. end;
  2138.  
  2139. { Mousedown method for FIP; used to allow dragging }
  2140. procedure TFileIconPanel.TheMouseDown(Sender: TObject;
  2141.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  2142. var ThePoint , TheOtherPoint : TPoint;
  2143. begin
  2144.   { Begin a conditional drag operation (false allows timer) }
  2145.   TheIOManager.WhichButton := Button;
  2146.   TheIOManager.WhichState := Shift;
  2147.   { Currently ignore drive clicks }
  2148.   if Pos( 'DRIVE' , FTheName ) > 0 then exit;
  2149.   if (( Button = mbRight ) and ( ssShift in Shift )) then
  2150.   begin
  2151.     TheTempBitmap := TBitmap.Create;
  2152.     TheTempBitmap.Width := Self.Width;
  2153.     TheTempBitmap.Height := Self.Height;
  2154.     TheTempBitmap.Canvas.Copyrect( Rect( 0 , 0 , Self.Width , Self.Height ) ,
  2155.      Self.Canvas , Rect( 0 , 0 , Self.Width , Self.Height ));
  2156.     TheMouseManager.InitializeBitmap( TheTempBitmap );
  2157.     ThePoint.X := X;
  2158.     ThePoint.Y := Y;
  2159.     TheOtherPoint := ClientToScreen( ThePoint );
  2160.     TheMouseManager.StartBitmapCursor( TheOtherPoint.X , TheOtherPoint.Y );
  2161.     BitmapDragging := true;
  2162.     GlobalSource := Self;
  2163.     exit;
  2164.   end;
  2165.   if Button = mbRight then
  2166.   begin
  2167.     TheMouseManager.InitializeIcon( FTheIcon );
  2168.     ThePoint.X := X;
  2169.     ThePoint.Y := Y;
  2170.     TheOtherPoint := ClientToScreen( ThePoint );
  2171.     TheMouseManager.StartIconCursor( TheOtherPoint.X , TheOtherPoint.Y );
  2172.     IconDragging := true;
  2173.     GlobalSource := Self;
  2174.     exit;
  2175.   end;
  2176.   BeginDrag( false );
  2177.   { Flip status of bevels }
  2178.   if BevelOuter = bvRaised then BevelOuter := bvLowered else
  2179.    BevelOuter := bvRaised;
  2180.   { Flip selected variable }
  2181.   Selected := not Selected;
  2182.   { Set redisplay }
  2183. end;
  2184.  
  2185. procedure TFileIconPanel.TheMouseMove(Sender: TObject; Shift: TShiftState;
  2186.   X, Y: Integer);
  2187. var ThePoint, TheOtherPoint : TPoint;
  2188. begin
  2189.   if IconDragging then
  2190.   begin
  2191.     ThePoint.X := X;
  2192.     ThePoint.Y := Y;
  2193.     TheOtherPoint := ClientToScreen( ThePoint );
  2194.     TheMouseManager.MoveIconCursor( TheOtherPoint.X , TheOtherPoint.Y );
  2195.     exit;
  2196.   end;
  2197.   if BitmapDragging then
  2198.   begin
  2199.     ThePoint.X := X;
  2200.     ThePoint.Y := Y;
  2201.     TheOtherPoint := ClientToScreen( ThePoint );
  2202.     TheMouseManager.MoveBitmapCursor( TheOtherPoint.X , TheOtherPoint.Y );
  2203.     exit;
  2204.   end;
  2205. end;
  2206.  
  2207. { Mouseup Method for FIP; used to allow dragging }
  2208. procedure TFileIconPanel.TheMouseUp(Sender: TObject;
  2209.   Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  2210. begin
  2211.   if IconDragging then
  2212.   begin
  2213.     TheMouseManager.EndIconCursor( X , Y );
  2214.     IconDragging := false;
  2215.     if GlobalSource <> Self then
  2216.     begin { Right-drag onto a panel! }
  2217.       TheDragDrop( Sender , GlobalSource , X , Y );
  2218.     end;
  2219.     exit;
  2220.   end;
  2221.   if BitmapDragging then
  2222.   begin
  2223.     TheMouseManager.EndBitmapCursor( X , Y );
  2224.     BitmapDragging := false;
  2225.     if GlobalSource <> Self then
  2226.     begin { Right-drag onto a panel! }
  2227.       TheDragDrop( Sender , GlobalSource , X , Y );
  2228.     end;
  2229.     exit;
  2230.   end;
  2231.   { End a drag operation without dropping; if dragged OK }
  2232.   { already handled.                                     }
  2233.   EndDrag( false );
  2234.   { If the right button is clicked, perform magic! }
  2235.   { Redisplay on general principles }
  2236.   Invalidate;
  2237. end;
  2238.  
  2239. { Use this to generically OK DnD from FIPs }
  2240. procedure TFileIconPanel.TheDragOver(Sender, Source: TObject; X,
  2241.   Y: Integer; State: TDragState; var Accept: Boolean);
  2242. begin
  2243.   { Only accept from FileIconPanel components }
  2244.   if Source is TFileIconPanel then Accept := true else Accept := false;
  2245. end;
  2246.  
  2247. { Use this to accept Drag and Drop from other FIPs }
  2248. procedure TFileIconPanel.TheDragDrop(Sender, Source: TObject; X,
  2249.   Y: Integer);
  2250. var CurrentName ,                 { Holds work name}
  2251.     TheOldString : String;        { Holds Dir      }
  2252.     TargetDir    : String;        { target of op   }
  2253.     TheResult       : Integer;    { Modal res hold }
  2254.     SourceDirectory,
  2255.     TargetDirectory,
  2256.     CurrentDirectory : String;    { Use to store dirs }
  2257.     TheDrive         : String;    { Get drive letter  }
  2258.     WhichDrive       : Integer;   { Get drive number  }
  2259.     ErrorCheck       : Integer;
  2260.     TheFWB           : TFileWorkBench;
  2261.     ThePosition : Integer;
  2262.     Finished : Boolean;
  2263.     TheFIPSB : TFileIconPanelScrollBox;
  2264. begin
  2265.   { If drop target is .. then ignore }
  2266.   if FTheLabel.Caption = '..' then exit;
  2267.   { Likewise ignore Dnd from drive icons }
  2268.   if Pos( 'DRIVE' , TFileIconPanel( Source ).FtheName ) > 0 then exit;
  2269.   { Obtain the parent of the source FIP; may not be self }
  2270.   TheFIPSB := TFileIconPanelScrollBox( TFileIconPanel( Source ).Parent );
  2271.   { Obtain source directory either as Dir or filepath }
  2272.   if (( FileGetAttr( TFileIconPanel( Source ).FTheName )
  2273.    and faDirectory ) = faDirectory ) then
  2274.   begin  { Directory; take whole path }
  2275.     SourceDirectory := TFileIconPanel( Source ).FTheName;
  2276.   end
  2277.   else
  2278.   begin { File; get pathname }
  2279.     SourceDirectory := ExtractFilePath( TFileIconPanel( Source ).FTheName );
  2280.   end;
  2281.   Sourcedirectory := TheFIPSB.TheFWB.ForceTrailingBackSlash( SourceDirectory );
  2282.   if Pos( 'DRIVE' , FTheName ) > 0 then
  2283.   begin { Drop onto a drive icon; perform action to its default dir }
  2284.     { Pull out the letter from name }
  2285.     TheDrive := Copy( FtheName , 7 , 1 );
  2286.     { Convert it to a number }
  2287.     WhichDrive := ( Ord( TheDrive[ 1 ] ) - Ord( 'A' )) + 1;
  2288.     { Determine the target directory and drive }
  2289.     GetDir( WhichDrive , TargetDirectory );
  2290.     TargetDirectory := TheFIPSB.TheFWB.ForceTrailingbackSlash( TargetDirectory );
  2291.     { Check for shift to operate on all selections }
  2292.     if TheIOManager.WasSHIFTPressed then
  2293.     begin { Operate on all selections }
  2294.       { Obtain the parent directory of the FIP dragged over }
  2295.       SourceDirectory := ExtractFilePath( TFileIconPanel( Source ).FTheName );
  2296.       SourceDirectory := TheFIPSB.TheFWB.ForceTrailingBackslash( SourceDirectory );
  2297.       { If SourceDir subset of TargetDir then abort; recursive failure }
  2298.       if Pos( SourceDirectory , TargetDirectory ) > 0 then
  2299.       begin
  2300.         MessageDlg( 'Cannot drag to same directory!',mtError,[mbOK],0 );
  2301.         exit;
  2302.       end;
  2303.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  2304.       begin { Copy to different drives }
  2305.         if TheIOManager.WasALTPressed then
  2306.         begin { ALT overrides and does move }
  2307.           { Set up to get all current selections }
  2308.           ThePosition := 1;
  2309.           finished := false;
  2310.           while not finished do
  2311.           begin
  2312.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2313.                    ThePosition );
  2314.             { If returns blank string then out of selections }
  2315.             if CurrentName = '' then finished := true else
  2316.             begin
  2317.               { If a directory signal error }
  2318.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2319.               begin
  2320.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  2321.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2322.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  2323.                    TargetDirectory );
  2324.               end
  2325.               else
  2326.               begin
  2327.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  2328.               end;
  2329.             end;
  2330.             { Reset to normal cursor }
  2331.             Screen.Cursor := crDefault;
  2332.           end;
  2333.         end
  2334.         else
  2335.         begin { Default is to do copy like file manager }
  2336.           { Set up to get all current selections }
  2337.           ThePosition := 1;
  2338.           finished := false;
  2339.           while not finished do
  2340.           begin
  2341.              CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2342.                    ThePosition );
  2343.             { If returns blank string then out of selections }
  2344.             if CurrentName = '' then finished := true else
  2345.             begin
  2346.               { If a directory signal error }
  2347.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2348.               begin
  2349.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  2350.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2351.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  2352.                    TargetDirectory );
  2353.               end
  2354.               else
  2355.               begin
  2356.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  2357.               end;
  2358.             end;
  2359.             { Reset to normal cursor }
  2360.             Screen.Cursor := crDefault;
  2361.           end;
  2362.         end;
  2363.       end
  2364.       else
  2365.       begin { Copy to same drive }
  2366.         if TheIOManager.WasCTRLPressed then
  2367.         begin { CTRL overrides and does copy }
  2368.           { Set up to get all current selections }
  2369.           ThePosition := 1;
  2370.           finished := false;
  2371.           while not finished do
  2372.           begin
  2373.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2374.                    ThePosition );
  2375.             { If returns blank string then out of selections }
  2376.             if CurrentName = '' then finished := true else
  2377.             begin
  2378.               { If a directory signal error }
  2379.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2380.               begin
  2381.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  2382.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2383.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  2384.                    TargetDirectory );
  2385.               end
  2386.               else
  2387.               begin
  2388.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  2389.               end;
  2390.             end;
  2391.             { Reset to normal cursor }
  2392.             Screen.Cursor := crDefault;
  2393.           end;
  2394.         end
  2395.         else
  2396.         begin { Default is to do move like file manager }
  2397.           { Set up to get all current selections }
  2398.           ThePosition := 1;
  2399.           finished := false;
  2400.           while not finished do
  2401.           begin
  2402.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2403.                    ThePosition );
  2404.             { If returns blank string then out of selections }
  2405.             if CurrentName = '' then finished := true else
  2406.             begin
  2407.               { If a directory signal error }
  2408.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2409.               begin
  2410.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  2411.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2412.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  2413.                    TargetDirectory );
  2414.               end
  2415.               else
  2416.               begin
  2417.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  2418.               end;
  2419.             end;
  2420.             { Reset to normal cursor }
  2421.             Screen.Cursor := crDefault;
  2422.           end;
  2423.         end;
  2424.       end;
  2425.     end
  2426.     else
  2427.     begin { Operate on only source }
  2428.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  2429.       begin { Copy to different drives }
  2430.         if TheIOManager.WasALTPressed then
  2431.         begin { ALT overrides and does move }
  2432.           with Source as TFileIconPanel do
  2433.           begin
  2434.             if MessageDlg( 'Move ' + FTheName + ' to ' +
  2435.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2436.               TheFIPSB.TheFWB.MoveTheFile( FTheName , TargetDirectory );
  2437.           end;
  2438.         end
  2439.         else
  2440.         begin { Default is to do copy like file manager }
  2441.           with Source as TFileIconPanel do
  2442.           begin
  2443.             if MessageDlg( 'Copy ' + FTheName + ' to ' +
  2444.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2445.               TheFIPSB.TheFWB.CopyTheFile( FtheName , TargetDirectory );
  2446.           end;
  2447.         end;
  2448.       end
  2449.       else
  2450.       begin { Copy to same drive }
  2451.         if TheIOManager.WasCTRLPressed then
  2452.         begin { CTRL overrides and does copy }
  2453.           with Source as TFileIconPanel do
  2454.           begin
  2455.             if MessageDlg( 'Copy ' + FTheName + ' to ' +
  2456.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2457.               TheFIPSB.TheFWB.CopyTheFile( FTheName , TargetDirectory );
  2458.           end;
  2459.         end
  2460.         else
  2461.         begin { Default is to do move like file manager }
  2462.           with Source as TFileIconPanel do
  2463.           begin
  2464.             if MessageDlg( 'Move ' + FTheName + ' to ' +
  2465.              TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2466.              TheFIPSB.TheFWB.MoveTheFile( FtheName , TargetDirectory );
  2467.           end;
  2468.         end;
  2469.       end;
  2470.     end;
  2471.   end
  2472.   else
  2473.   begin { Drop onto dir or file icon }
  2474.     if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  2475.     begin { Drop onto a directory; use its path as target }
  2476.       TargetDirectory := FTheName;
  2477.     end
  2478.     else
  2479.     begin { Drop onto a file; use its parent as target }
  2480.       TargetDirectory := ExtractFilePath( FTheName );
  2481.     end;
  2482.     Targetdirectory := TheFIPSB.TheFWB.ForceTrailingbackslash( TargetDirectory );
  2483.     { Check for shift to operate on all selections }
  2484.     if TheIOManager.WasSHIFTPressed then
  2485.     begin { Operate on all selections }
  2486.       { Obtain the parent directory of the FIP dragged over }
  2487.       SourceDirectory := ExtractFilePath( TFileIconPanel( Source ).FTheName );
  2488.       SourceDirectory := TheFIPSB.TheFWB.ForceTrailingBackslash( SourceDirectory );
  2489.       { If SourceDir subset of TargetDir then abort; recursive failure }
  2490.       if Pos( SourceDirectory , TargetDirectory ) > 0 then
  2491.       begin
  2492.         MessageDlg( 'Cannot drag to same directory!',mtError,[mbOK],0 );
  2493.         exit;
  2494.       end;
  2495.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  2496.       begin { Copy to different drives }
  2497.         if TheIOManager.WasALTPressed then
  2498.         begin { ALT overrides and does move }
  2499.           { Set up to get all current selections }
  2500.           ThePosition := 1;
  2501.           finished := false;
  2502.           while not finished do
  2503.           begin
  2504.              CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2505.                    ThePosition );
  2506.             { If returns blank string then out of selections }
  2507.             if CurrentName = '' then finished := true else
  2508.             begin
  2509.               { If a directory signal error }
  2510.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2511.               begin
  2512.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  2513.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2514.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  2515.                    TargetDirectory );
  2516.               end
  2517.               else
  2518.               begin
  2519.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  2520.               end;
  2521.             end;
  2522.             { Reset to normal cursor }
  2523.             Screen.Cursor := crDefault;
  2524.           end;
  2525.         end
  2526.         else
  2527.         begin { Default is to do copy like file manager }
  2528.           { Set up to get all current selections }
  2529.           ThePosition := 1;
  2530.           finished := false;
  2531.           while not finished do
  2532.           begin
  2533.             CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2534.                    ThePosition );
  2535.             { If returns blank string then out of selections }
  2536.             if CurrentName = '' then finished := true else
  2537.             begin
  2538.               { If a directory signal error }
  2539.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2540.               begin
  2541.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  2542.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2543.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  2544.                    TargetDirectory );
  2545.               end
  2546.               else
  2547.               begin
  2548.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  2549.               end;
  2550.             end;
  2551.             { Reset to normal cursor }
  2552.             Screen.Cursor := crDefault;
  2553.           end;
  2554.         end;
  2555.       end
  2556.       else
  2557.       begin { Copy to same drive }
  2558.         if TheIOManager.WasCTRLPressed then
  2559.         begin { CTRL overrides and does copy }
  2560.           { Set up to get all current selections }
  2561.           ThePosition := 1;
  2562.           finished := false;
  2563.           while not finished do
  2564.           begin
  2565.             { Call generic file getting routine based on current view}
  2566.              CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2567.                    ThePosition );
  2568.             { If returns blank string then out of selections }
  2569.             if CurrentName = '' then finished := true else
  2570.             begin
  2571.               { If a directory signal error }
  2572.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2573.               begin
  2574.                 if MessageDlg( 'Copy Directory ' + CurrentName + ' to ' +
  2575.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2576.                   TheFIPSB.TheFWB.RecursivelyCopyDirectory( CurrentName ,
  2577.                    TargetDirectory );
  2578.               end
  2579.               else
  2580.               begin
  2581.                 TheFIPSB.TheFWB.CopyTheFile( CurrentName , TargetDirectory );
  2582.               end;
  2583.             end;
  2584.             { Reset to normal cursor }
  2585.             Screen.Cursor := crDefault;
  2586.           end;
  2587.         end
  2588.         else
  2589.         begin { Default is to do move like file manager }
  2590.           { Set up to get all current selections }
  2591.           ThePosition := 1;
  2592.           finished := false;
  2593.           while not finished do
  2594.           begin
  2595.             { Call generic file getting routine based on current view}
  2596.               CurrentName := TheFIPSB.GetNextSelection( SourceDirectory ,
  2597.                    ThePosition );
  2598.             { If returns blank string then out of selections }
  2599.             if CurrentName = '' then finished := true else
  2600.             begin
  2601.               { If a directory signal error }
  2602.               if (( FileGetAttr( CurrentName ) and faDirectory ) = faDirectory ) then
  2603.               begin
  2604.                 if MessageDlg( 'Move Directory ' + CurrentName + ' to ' +
  2605.                  TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2606.                   TheFIPSB.TheFWB.RecursivelyMoveDirectory( CurrentName ,
  2607.                    TargetDirectory );
  2608.               end
  2609.               else
  2610.               begin
  2611.                 TheFIPSB.TheFWB.MoveTheFile( CurrentName , TargetDirectory );
  2612.               end;
  2613.             end;
  2614.             { Reset to normal cursor }
  2615.             Screen.Cursor := crDefault;
  2616.           end;
  2617.         end;
  2618.       end;
  2619.     end
  2620.     else
  2621.     begin { Operate on only source }
  2622.       if TargetDirectory[ 1 ] <> SourceDirectory[ 1 ] then
  2623.       begin { Copy to different drives }
  2624.         if TheIOManager.WasALTPressed then
  2625.         begin { ALT overrides and does move }
  2626.           with Source as TFileIconPanel do
  2627.           begin
  2628.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  2629.             begin
  2630.               if MessageDlg( 'Move Directory ' + FTheName + ' to ' +
  2631.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2632.                 TheFIPSB.TheFWB.RecursivelyMoveDirectory( FtheName ,
  2633.                  TargetDirectory );
  2634.             end
  2635.             else
  2636.             begin
  2637.               if MessageDlg( 'Move ' + FTheName + ' to ' +
  2638.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2639.                 TheFIPSB.TheFWB.MoveTheFile( FTheName , TargetDirectory );
  2640.             end;
  2641.           end;
  2642.         end
  2643.         else
  2644.         begin { Default is to do copy like file manager }
  2645.           with Source as TFileIconPanel do
  2646.           begin
  2647.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  2648.             begin
  2649.               if MessageDlg( 'Copy Directory ' + FtheName + ' to ' +
  2650.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2651.                 TheFIPSB.TheFWB.RecursivelyCopyDirectory( FtheName ,
  2652.                  TargetDirectory );
  2653.             end
  2654.             else
  2655.             begin
  2656.               if MessageDlg( 'Copy ' + FTheName + ' to ' +
  2657.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2658.                 TheFIPSB.TheFWB.CopyTheFile( FTheName , TargetDirectory );
  2659.             end;
  2660.           end;
  2661.         end;
  2662.       end
  2663.       else
  2664.       begin { Copy to same drive }
  2665.         if TheIOManager.WasCTRLPressed then
  2666.         begin { CTRL overrides and does copy }
  2667.           with Source as TFileIconPanel do
  2668.           begin
  2669.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  2670.             begin
  2671.               if MessageDlg( 'Copy Directory ' + FtheName + ' to ' +
  2672.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2673.                 TheFIPSB.TheFWB.RecursivelyCopyDirectory( FtheName ,
  2674.                  TargetDirectory );
  2675.             end
  2676.             else
  2677.             begin
  2678.               if MessageDlg( 'Copy ' + FTheName + ' to ' +
  2679.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2680.                 TheFIPSB.TheFWB.CopyTheFile( FTheName , TargetDirectory );
  2681.             end;
  2682.           end;
  2683.         end
  2684.         else
  2685.         begin { Default is to do move like file manager }
  2686.           with Source as TFileIconPanel do
  2687.           begin
  2688.             if (( FileGetAttr( FTheName ) and faDirectory ) = faDirectory ) then
  2689.             begin
  2690.               if MessageDlg( 'Move Directory ' + FtheName + ' to ' +
  2691.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2692.                 TheFIPSB.TheFWB.RecursivelyMoveDirectory( FtheName ,
  2693.                  TargetDirectory );
  2694.             end
  2695.             else
  2696.             begin
  2697.               if MessageDlg( 'Move ' + FTheName + ' to ' +
  2698.                TargetDirectory + '?' , mtConfirmation , mbYesNoCancel , 0 ) = mrYes then
  2699.                 TheFIPSB.TheFWB.MoveTheFile( FTheName , TargetDirectory );
  2700.             end;
  2701.           end;
  2702.         end;
  2703.       end;
  2704.     end;
  2705.   end;
  2706.   { Call special method due to SendMessage problem! }
  2707.   TFileIconPanelScrollBox( TFileIconPanel( Source ).Parent ).Update;
  2708.   TFileIconPanelScrollBox( Parent ).Update;
  2709. end;
  2710.  
  2711. { Paint method for FIP; overrides normal paint }
  2712. procedure TFileIconPanel.Paint;
  2713. var
  2714.   TheOtherRect   : TRect;   { Holds clientrect   }
  2715.   TopColor     ,            { Holds bright color }
  2716.   BottomColor    : TColor;  { Holds dark color   }
  2717.  
  2718. { These methods are from Borland Intl., copyright 1995 }
  2719. procedure Frame3D(    Canvas       : TCanvas;
  2720.                   var TheRect      : TRect;
  2721.                       TopColor   ,
  2722.                       BottomColor  : TColor;
  2723.                       Width        : Integer );
  2724.  
  2725. procedure DoRect;
  2726. var
  2727.   TopRight, BottomLeft: TPoint;
  2728. begin
  2729.   with Canvas, TheRect do
  2730.   begin
  2731.     TopRight.X := Right;
  2732.     TopRight.Y := Top;
  2733.     BottomLeft.X := Left;
  2734.     BottomLeft.Y := Bottom;
  2735.     Pen.Color := TopColor;
  2736.     PolyLine([BottomLeft, TopLeft, TopRight]);
  2737.     Pen.Color := BottomColor;
  2738.     Dec(BottomLeft.X);
  2739.     PolyLine([TopRight, BottomRight, BottomLeft]);
  2740.   end;
  2741. end;
  2742.  
  2743. begin
  2744.   Canvas.Pen.Width := 1;
  2745.   Dec(TheRect.Bottom); Dec(TheRect.Right);
  2746.   while Width > 0 do
  2747.   begin
  2748.     Dec(Width);
  2749.     DoRect;
  2750.     InflateRect(TheRect, -1, -1);
  2751.   end;
  2752.   Inc(TheRect.Bottom); Inc(TheRect.Right);
  2753. end;
  2754.  
  2755. procedure AdjustColors(Bevel: TPanelBevel);
  2756. begin
  2757.   TopColor := FHighlightColor;
  2758.   if Bevel = bvLowered then TopColor := FShadowColor;
  2759.   BottomColor := FShadowColor;
  2760.   if Bevel = bvLowered then BottomColor := FHighlightColor;
  2761. end;
  2762.  
  2763. { Custom code begins here }
  2764. begin
  2765.   { Get the rectangle of the control with API/method call }
  2766.   TheOtherRect := GetClientRect;
  2767.   { draw basic rectangle with basic color }
  2768.   with Canvas do
  2769.   begin
  2770.     Brush.Color := Color;
  2771.     FillRect(TheOtherRect);
  2772.   end;
  2773.   { Set up for top "icon" frame  and draw it with frame3d }
  2774.   TheOtherRect.Right := Width;
  2775.   TheOtherRect.Bottom := Round( Height * 0.75 ) - 6 ;
  2776.   if BevelOuter <> bvNone then
  2777.   begin
  2778.     AdjustColors(BevelOuter);
  2779.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  2780.   end;
  2781.   Frame3D(Canvas, TheOtherRect, Color, Color, BorderWidth);
  2782.   if BevelInner <> bvNone then
  2783.   begin
  2784.     AdjustColors(BevelInner);
  2785.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  2786.   end;
  2787.   { Do the same for the lower "label" frame }
  2788.   TheOtherRect.Top := Round( Height * 0.75 ) - 5;
  2789.   TheOtherRect.Left := 0;
  2790.   TheOtherRect.Bottom := Height;
  2791.   TheOtherRect.Right := Width;
  2792.   if BevelOuter <> bvNone then
  2793.   begin
  2794.     AdjustColors(BevelOuter);
  2795.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  2796.   end;
  2797.   Frame3D(Canvas, TheOtherRect, Color, Color, BorderWidth);
  2798.   if BevelInner <> bvNone then
  2799.   begin
  2800.     AdjustColors(BevelInner);
  2801.     Frame3D(Canvas, TheOtherRect, TopColor, BottomColor, BevelWidth);
  2802.   end;
  2803.   if Assigned( FTheBMP ) then
  2804.   begin
  2805.     Canvas.Draw( (( Width - ThumbNailWidth ) div 2 ) ,
  2806.     ((( Round( Height * 0.75 ) - 6 ) - ThumbNailHeight ) div 2 ) , FTheBMP );
  2807.   end
  2808.   else
  2809.   begin
  2810.     { Then draw the icon using canvas draw method }
  2811.     Canvas.Draw( (( Width - 32 ) div 2 ) + 1 ,
  2812.     ((( Round( Height * 0.75 ) - 6 ) - 32 ) div 2 ) + 1 , FTheIcon );
  2813.   end;
  2814. end;
  2815.  
  2816. { This procedure clears a scrollbox of all FileIconPanels }
  2817. procedure TFileIconPanelScrollbox.ClearTheFIPs;
  2818. var Counter_1 : Integer;
  2819.     TheComponent : TComponent;
  2820. begin
  2821.   { Note that must use while loop since component count continually }
  2822.   { decreases as removes are made!                                  }
  2823.   while ComponentCount > 0 do
  2824.   begin
  2825.     { Save the component as a generic TComponent }
  2826.     TheComponent := Components[ 0 ];
  2827.     { Call removecomponent to pull it out of the owner list for sb }
  2828.     { This avoids GPF when freeing the sb.                         }
  2829.     RemoveComponent( Components[ 0 ]);
  2830.     if ControlCount > 0 then
  2831.      RemoveControl( Controls[ 0 ] );
  2832.     { Typecast the pointer and free it to release memory and res. }
  2833.     TheParentForm.InsertComponent( TheComponent );
  2834.   end;
  2835. end;
  2836.  
  2837. { This procedure scans for drives and obtains their type and creates file }
  2838. { icon panels to represent them.                                          }
  2839. procedure TFileIconPanelScrollBox.AddDriveIcons( var XCounter ,
  2840.            YCounter : Integer );
  2841. type
  2842.   { This if from filectrl unit; reproduce here for completeness }
  2843.   TDriveType = (dtUnknown, dtNoDrive, dtFloppy, dtFixed, dtNetwork, dtCDROM,
  2844.                 dtRAM);
  2845. var
  2846.   DriveNum        : Integer;         { Used to get next drive via DOS fn   }
  2847.   IconType        : Integer;         { Used to hold icon type (defacto dt) }
  2848.   DriveChar       : Char;            { Used to hold drive letter           }
  2849.   DriveType       : TDriveType;      { Used for set-valued drive type      }
  2850.   Finished        : Boolean;         { Loop flag                           }
  2851.   TheFIP          : TFileIconPanel;  { Generic FileIconPanel variable      }
  2852.   ButtonColor   ,                    { Main panel color                    }
  2853.   ButtonHLColor ,                    { Bright panel color                  }
  2854.   ButtonSColor  ,                    { Dark panel color                    }
  2855.   Textcolor       : TColor;          { Label text color                    }
  2856.  
  2857. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  2858. { Check whether drive is a CD-ROM.  Returns True if MSCDEX is installed }
  2859. {  and the drive is using a CD driver                                   }
  2860.  
  2861. function IsCDROM(DriveNum: Integer): Boolean; assembler;
  2862. asm
  2863.   MOV   AX,1500h { look for MSCDEX }
  2864.   XOR   BX,BX
  2865.   INT   2fh
  2866.   OR    BX,BX
  2867.   JZ    @Finish
  2868.   MOV   AX,150Bh { check for using CD driver }
  2869.   MOV   CX,DriveNum
  2870.   INT   2fh
  2871.   OR    AX,AX
  2872.   @Finish:
  2873. end;
  2874.  
  2875. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  2876. { Check whether drive is a RAM drive.                                   }
  2877. function IsRAMDrive(DriveNum: Integer): Boolean; assembler;
  2878. var
  2879.   TempResult: Boolean;
  2880. asm
  2881.   MOV   TempResult,False
  2882.   PUSH  DS
  2883.   MOV   BX,SS
  2884.   MOV   DS,BX
  2885.   SUB   SP,0200h
  2886.   MOV   BX,SP
  2887.   MOV   AX,DriveNum
  2888.   MOV   CX,1
  2889.   XOR   DX,DX
  2890.   INT   25h  { read boot sector }
  2891.   ADD   SP,2
  2892.   JC    @ItsNot
  2893.   MOV   BX,SP
  2894.   CMP   BYTE PTR SS:[BX+15h],0F8h  { reverify fixed disk }
  2895.   JNE   @ItsNot
  2896.   CMP   BYTE PTR SS:[BX+10h],1  { check for single FAT }
  2897.   JNE   @ItsNot
  2898.   MOV   TempResult,True
  2899.   @ItsNot:
  2900.   ADD   SP,0200h
  2901.   POP   DS
  2902.   MOV   AL, TempResult
  2903. end;
  2904.  
  2905. { This code is from the FileCtrl Unit; copyright Borland Intl 1995      }
  2906. { Finds the type of a drive letter.                                     }
  2907. function FindDriveType(DriveNum: Integer): TDriveType;
  2908. begin
  2909.   Result := TDriveType(GetDriveType(DriveNum));
  2910.   if (Result = dtFixed) or (Result = dtNetwork) then
  2911.   begin
  2912.     if IsCDROM(DriveNum) then Result := dtCDROM
  2913.     else if (Result = dtFixed) then
  2914.     begin
  2915.         { do not check for RAMDrive under Windows NT }
  2916.       if ((GetWinFlags and $4000) = 0) and IsRAMDrive(DriveNum) then
  2917.         Result := dtRAM;
  2918.     end;
  2919.   end;
  2920. end;
  2921.  
  2922. begin
  2923.   { Set the button colors to an aquamarine color scheme for drives }
  2924.   ButtonColor := clTeal;
  2925.   ButtonHLColor := clAqua;
  2926.   ButtonSColor := clNavy;
  2927.   TextColor := clblack;
  2928.   { Set initial variables before looping for all drives }
  2929.   finished := false;
  2930.   DriveNum := 0;
  2931.   while not finished do
  2932.   begin
  2933.     { Start with no drive found }
  2934.     IconType := 0;
  2935.     { Call the Borland method to get the drive info }
  2936.     DriveType := FindDriveType(DriveNum);
  2937.     { Set its letter and make it uppercase }
  2938.     DriveChar := Chr(DriveNum + ord('a'));
  2939.     DriveChar := Upcase(DriveChar);
  2940.     { Assign an icon based on the drive type; if no drive exists type is nil }
  2941.     case DriveType of
  2942.       dtFloppy  : IconType := 1;
  2943.       dtFixed   : IconType := 2;
  2944.       dtNetwork : IconType := 3;
  2945.       dtCDROM   : IconType := 4;
  2946.       dtRAM     : IconType := 5;
  2947.     end;
  2948.     { Set to check next drive letter }
  2949.     DriveNum := DriveNum + 1;
  2950.     { But if no match then out of drives so set exit flag }
  2951.     if IconType = 0 then finished := true;
  2952.     { If drive was valid then set up the New FileIconPanel on the imported }
  2953.     { Scrollbox                                                            }
  2954.     if not finished then
  2955.     begin
  2956.       { Create the FileIconPanel and set its parent for memory mgmt and display}
  2957.       TheFIP := TFileIconPanel.Create( Self );
  2958.       TheFIP.Parent := Self;
  2959.       { Call its initialize method with imported position values and the   }
  2960.       { preset color scheme, a drive caption, and a minimum font. Note the }
  2961.       { setting of the ExtraData field to non-zero; this signals a drive   }
  2962.       { rather than a file being sent in.                                  }
  2963.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  2964.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  2965.         7 , ButtonColor, ButtonHLColor,
  2966.        ButtonSColor , TextColor , 'DRIVE ' + DriveChar + ':' , 'MS Serif' , [] ,
  2967.        IconType );
  2968.       { Increment the column counter; if it exceeds max move to New row      }
  2969.       { Note that these are 'var' parameters and will export final position. }
  2970.       XCounter := XCounter + 1;
  2971.       if XCounter > MaxIconsInARow then
  2972.       begin
  2973.         XCounter := 1;
  2974.         YCounter := YCounter + 1;
  2975.       end;
  2976.     end;
  2977.   end;
  2978. end;
  2979.  
  2980. { This procedure assigns colors to FIP's based on file attributes }
  2981. procedure TFileIconPanelScrollBox.GetColorsForFileIcon( TheFile : String;
  2982.            var BC , HC , SC , TC : TColor );
  2983. var AmADir      ,             { Booleans hold file attribs }
  2984.     AmAnArchive ,
  2985.     AmAVolumeId ,
  2986.     AmHidden    ,
  2987.     AmReadOnly  ,
  2988.     AmSystem      : Boolean;
  2989. begin
  2990.   { Make the call to internal fileworkbench to set attributes }
  2991.   TheFWB.GetFileAttributes( TheFile , AmADir , AmAnArchive , AmAVolumeId ,
  2992.    AmHidden , AmReadOnly , AmSystem );
  2993.   { Volume ID has no subtypes }
  2994.   if AmAVolumeID then
  2995.   begin
  2996.     BC := clOlive;
  2997.     HC := clYellow;
  2998.     SC := clBlack;
  2999.     TC := clWhite;
  3000.     exit;
  3001.   end;
  3002.   { Check all directory combinations }
  3003.   if AmADir then
  3004.   begin
  3005.     BC := clNavy;
  3006.     HC := clBlue;
  3007.     SC := clBlack;
  3008.     TC := clWhite;
  3009.     if AmHidden then
  3010.     begin
  3011.       if AmReadOnly then
  3012.       begin
  3013.         if AmSystem then
  3014.         begin { One HECK of a file! }
  3015.           BC := clBlack;
  3016.           HC := clSilver;
  3017.           SC := clGray;
  3018.           TC := clWhite;
  3019.         end
  3020.         else
  3021.         begin { Dir,RO,Hid }
  3022.           BC := clMaroon;
  3023.           HC := clFuchsia;
  3024.           SC := clGreen;
  3025.           TC := clWhite;
  3026.         end;
  3027.       end
  3028.       else
  3029.       begin { Dir,Hid }
  3030.         BC := clPurple;
  3031.         HC := clFuchsia;
  3032.         SC := clBlack;
  3033.         TC := clWhite;
  3034.       end;
  3035.     end
  3036.     else
  3037.     begin
  3038.       if AmReadOnly then
  3039.       begin
  3040.         if AmSystem then
  3041.         begin { Dir,RO,Sys }
  3042.           BC := clMaroon;
  3043.           HC := clLime;
  3044.           SC := clGreen;
  3045.           TC := clWhite;
  3046.         end
  3047.         else
  3048.         begin { Dir,RO }
  3049.           BC := clGreen;
  3050.           HC := clLime;
  3051.           SC := clBlack;
  3052.           TC := clWhite;
  3053.         end;
  3054.       end
  3055.       else
  3056.       begin
  3057.         if AmSystem then
  3058.         begin { Dir,Sys }
  3059.           BC := clMaroon;
  3060.           HC := clRed;
  3061.           SC := clBlack;
  3062.           TC := clWhite;
  3063.         end;
  3064.       end;
  3065.     end;
  3066.   end
  3067.   else { Archive Only; check all combinations }
  3068.   begin
  3069.     BC := clSilver;
  3070.     HC := clWhite;
  3071.     SC := clGray;
  3072.     TC := clBlack;
  3073.     if AmHidden then
  3074.     begin
  3075.       if AmReadOnly then
  3076.       begin
  3077.         if AmSystem then
  3078.         begin { Hid,RO,Sys }
  3079.           BC := clRed;
  3080.           HC := clLime;
  3081.           SC := clPurple;
  3082.           TC := clBlack;
  3083.         end
  3084.         else
  3085.         begin { RO,Hid }
  3086.           BC := clLime;
  3087.           HC := clFuchsia;
  3088.           SC := clMaroon;
  3089.           TC := clBlack;
  3090.         end;
  3091.       end
  3092.       else
  3093.       begin { Hid }
  3094.         BC := clFuchsia;
  3095.         HC := clWhite;
  3096.         SC := clPurple;
  3097.         TC := clBlack;
  3098.       end;
  3099.     end
  3100.     else
  3101.     begin
  3102.       if AmReadOnly then
  3103.       begin
  3104.         if AmSystem then
  3105.         begin { RO,Sys }
  3106.           BC := clRed;
  3107.           HC := clLime;
  3108.           SC := clMaroon;
  3109.           TC := clBlack;
  3110.         end
  3111.         else
  3112.         begin { RO }
  3113.           BC := clLime;
  3114.           HC := clWhite;
  3115.           SC := clGreen;
  3116.           TC := clBlack;
  3117.         end;
  3118.       end
  3119.       else
  3120.       begin
  3121.         if AmSystem then
  3122.         begin { System }
  3123.           BC := clRed;
  3124.           HC := clWhite;
  3125.           SC := clMaroon;
  3126.           TC := clBlack;
  3127.         end;
  3128.       end;
  3129.     end;
  3130.   end;
  3131. end;
  3132.  
  3133. { This procedure gets all icons for an given directory, including drives and }
  3134. { standard subdirectories. It does not get special combinations or h/ro/sys  }
  3135. procedure TFileIconPanelScrollbox.GetIconsForEntireDirectory(
  3136.             TargetPath  : String );
  3137. var Finished        : Boolean;         { Loop flag              }
  3138.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  3139.     TheResult       : Integer;         { return variable        }
  3140.     TempPath        : String;          { path for FF/FN         }
  3141.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  3142.     RowCounter    ,                    { position in row of FIP }
  3143.     ColumnCounter   : Integer;         { position in col of FIP }
  3144.     ButtonColor   ,                    { main panel color       }
  3145.     ButtonHLColor ,                    { bright panel color     }
  3146.     ButtonSColor  ,                    { dark panel color       }
  3147.     Textcolor       : TColor;          { label text color       }
  3148.     IsADir ,                           { Variable for file attr }
  3149.     IsAnArchive ,
  3150.     IsAVolumeID,
  3151.     IsAReadOnlyFile,
  3152.     IsAHiddenFile ,
  3153.     IsASystemFile     : Boolean;
  3154.     MaxTextLength     : Integer;       { Used to safely set size}
  3155. begin
  3156.   { hide during refresh }
  3157.   Visible := false;
  3158.   { Get the icon sizes }
  3159.   TheFIP := TFileIconPanel.Create( Self );
  3160.   TheFIP.Parent := Self;
  3161.   TheFIP.FTheLabel.Canvas.Font.Name := 'MS Serif';
  3162.   TheFIP.FTheLabel.Canvas.Font.Size := 7;
  3163.   MaxTextLength := TheFIP.FTheLabel.Canvas.TextWidth( 'COMMAND.COM' );
  3164.   TheFIP.Free;
  3165.   TheIconSize := MaxTextLength + 13;
  3166.   ThumbNailWidth := TheIconSize - 10;
  3167.   ThumbNailHeight := Round( TheIconSize * 0.75 ) - 15;
  3168.   TheIconSpacing := TheIconSize + 5;
  3169.   { Set up maximum icons per row based on screen size }
  3170.   MaxIconsInARow := ( Screen.Width div TheIconSpacing );
  3171.   { Set up the position counters }
  3172.   RowCounter := 1;
  3173.   ColumnCounter := 1;
  3174.   { Get the drives for the current machine }
  3175.   AddDriveIcons( ColumnCounter , RowCounter  );
  3176.   { Set up the initial variables }
  3177.   Finished := false;
  3178.   TempPath := TargetPath + '*.*';
  3179.   { Make the call to FindFirst set to get any file; will return '.' }
  3180.   { so discard it.                                                  }
  3181.   TheResult := FindFirst( TempPath , faAnyFile , TheSR );
  3182.   { loop through all files in the directory and look for directories }
  3183.   while not Finished do
  3184.   begin
  3185.     { Make call to FindNext, using only SearchRecord from FindFirst }
  3186.     TheResult := FindNext( TheSR );
  3187.     { A -1 result means no more files so exit }
  3188.     if TheResult < 0 then finished := true else
  3189.     begin
  3190.       { Otherwise check for a directory attribute }
  3191.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  3192.        faDirectory ) then
  3193.       begin
  3194.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3195.          ButtonHLColor , ButtonSColor , TextColor );
  3196.         { If found create a New FileIconPanel on the imported scrollbox }
  3197.         { Note sending 0 ExtraData parameter to indicate file not drive }
  3198.         TheFIP := TFileIconPanel.Create( Self );
  3199.         TheFIP.Parent := Self;
  3200.         TheFIP.Initialize((( ColumnCounter - 1 ) * TheIconSpacing ),
  3201.          (( RowCounter - 1  ) * TheIconSpacing ) , TheIconSize, TheIconSize ,
  3202.           3 , 7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  3203.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  3204.         { Increment column counter and move to New row if past limit }
  3205.         ColumnCounter := ColumnCounter + 1;
  3206.         if ColumnCounter > MaxIconsInARow then
  3207.         begin
  3208.           ColumnCounter := 1;
  3209.           RowCounter := RowCounter + 1;
  3210.         end;
  3211.       end;
  3212.     end;
  3213.   end;
  3214.   { Call FindClose for Windows NT/Windows 95 compatibility }
  3215.   FindClose( TheSR );
  3216.   { Set up New initialization variables }
  3217.   Finished := false;
  3218.   TempPath := TargetPath + '*.*';
  3219.   { Make needed call to FindFirst and discard '.' }
  3220.   TheResult := FindFirst( TempPath , faAnyFile , TheSR );
  3221.   while not Finished do
  3222.   begin
  3223.     { Loop through file again, this time getting only archive files }
  3224.     TheResult := FindNext( TheSR );
  3225.     { Result of -1 indicates no more files }
  3226.     if TheResult < 0 then Finished := true else
  3227.     begin
  3228.       { If faArchive file then add New FileIconPanel }
  3229.       TheFWB.GetFileAttributes(( Targetpath + TheSR.Name ) , IsADir ,
  3230.        IsAnArchive , IsAVolumeId , IsAHiddenFile , IsAReadOnlyFile ,
  3231.         IsASystemFile );
  3232.       if (( IsAnArchive ) and ( not IsADir )) then
  3233.       begin
  3234.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3235.          ButtonHLColor , ButtonSColor , TextColor );
  3236.         { Initialize New FileIconPanel and call initialize, sending 0 ED }
  3237.         TheFIP := TFileIconPanel.Create( Self );
  3238.         TheFIP.Parent := Self;
  3239.         TheFIP.Initialize((( ColumnCounter - 1 ) * TheIconSpacing ),
  3240.          (( RowCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize ,
  3241.           3 , 7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  3242.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  3243.         { Increment column counter and if needed row counter }
  3244.         ColumnCounter := ColumnCounter + 1;
  3245.         if ColumnCounter > MaxIconsInARow then
  3246.         begin
  3247.           ColumnCounter := 1;
  3248.           RowCounter := RowCounter + 1;
  3249.         end;
  3250.       end;
  3251.     end;
  3252.   end;
  3253.   { Call findclose for w95 and exit }
  3254.   FindClose( TheSR );
  3255.   { Reset to visible }
  3256.   Visible := true;
  3257. end;
  3258.  
  3259. { Update method for FIPscrollbox }
  3260. procedure TFileIconPanelScrollBox.Update;
  3261. begin
  3262.   IconsNeedRefreshing := true;
  3263.   { Force a repaint }
  3264.   InvalidateRect( TheStoredHandle , nil , true );
  3265. end;
  3266.  
  3267. { Create method for FIPScrollbox }
  3268. constructor TFileIconPanelScrollBox.Create( AOwner : TComponent );
  3269. begin
  3270.   inherited Create( AOwner );
  3271.   TheFWB := TFileWorkBench.Create( Self );
  3272. end;
  3273.  
  3274. { This function returns the next selected file's name }
  3275. function TFileIconPanelScrollBox.GetNextSelection( SourceDirectory : String;
  3276.                            var CurrentItem : Integer ) : String;
  3277. var TheResult    : String;      { Holds result of function }
  3278.     TheComponent : TComponent;  { Used for typecast        }
  3279.     finished     : boolean;     { Loop control variable    }
  3280.     TheComponentCount : Integer;
  3281. begin
  3282.   TheComponentCount := ComponentCount;
  3283.   { If past end of components exit with no result }
  3284.   if CurrentItem > TheComponentCount then TheResult := '' else
  3285.   begin
  3286.     { Set loop counter and run till find match or run out }
  3287.     finished := false;
  3288.     while not finished do
  3289.     begin
  3290.       { Pull component out of the list and check it }
  3291.       TheComponent := Components[ CurrentItem - 1 ];
  3292.       { Increment counter for later }
  3293.       CurrentItem := CurrentItem + 1;
  3294.       { Do the typecast with AS }
  3295.       if TheComponent is TFileIconPanel then
  3296.       with TheComponent as TFileIconPanel do
  3297.       begin
  3298.         { If its selected make sure OK }
  3299.         if Selected then
  3300.         begin
  3301.           { Don't accept backup for this level of operation }
  3302.           if FTheLabel.Caption <> '..' then
  3303.           begin
  3304.             { Otherwise return the name and abort the loop }
  3305.             TheResult := FTheName;
  3306.             finished := true;
  3307.           end;
  3308.         end
  3309.         else
  3310.         begin
  3311.           { Check to see if out of components }
  3312.           if CurrentItem > TheComponentCount then
  3313.           begin
  3314.             { If so signal error and abort }
  3315.             TheResult := '';
  3316.             finished := true;
  3317.           end;
  3318.         end;
  3319.       end;
  3320.     end;
  3321.   end;
  3322.   GetNextSelection := TheResult;
  3323. end;
  3324.  
  3325. { This procedure places a selection of files in the display based on wildcards }
  3326. procedure TFileIconPanelScrollBox.DisplayRecursiveSearchResults(
  3327.            TheStartingDirectory : String );
  3328. var XCounter ,
  3329.     YCounter   : Integer;
  3330.  
  3331. { This procedure does a recursive file search by first getting all matches (in-}
  3332. { cluding directories) and adding them to the list. Then it checks for ALL the }
  3333. { subdirectories and does the same trick on them til there are no more matches }
  3334. { and no more subdirectories, at which point it exits and recurses back up.    }
  3335. procedure RecursiveFileSearch( TheWorkingDirectory : String; var XCounter ,
  3336.                                YCounter : Integer );
  3337.  
  3338. { VITAL!!! These variables MUST be local for recursrion to work! }
  3339. var
  3340.     Finished        : Boolean;         { Loop flag              }
  3341.     TheSR           : TSearchRec;      { Searchrecord for FF/FN }
  3342.     TheResult       : Integer;         { return variable        }
  3343.     TargetPath ,
  3344.     FileMask   ,
  3345.     TheStoredWorkingDirectory ,
  3346.     ModifiedDirectory  : String;       { path for FF/FN         }
  3347.     TheFIP          : TFileIconPanel;  { generic FIP holder     }
  3348.     ButtonColor   ,                    { main panel color       }
  3349.     ButtonHLColor ,                    { bright panel color     }
  3350.     ButtonSColor  ,                    { dark panel color       }
  3351.     Textcolor       : TColor;          { label text color       }
  3352.  
  3353. begin
  3354.   { Jump out if abort pressed }
  3355.   if GlobalAbortFlag then exit;
  3356.   { Set up the initial variables }
  3357.   Finished := false;
  3358.   TheStoredWorkingDirectory := TheWorkingDirectory;
  3359.   Targetpath := ExtractFilePath( TheWorkingDirectory );
  3360.   FileMask := ExtractFileName( TheWorkingDirectory );
  3361.   { Make the call to FindFirst set to get any file }
  3362.   TheResult := FindFirst( TheWorkingDirectory , faAnyFile , TheSR );
  3363.   if TheResult < 0 then finished := true;
  3364.   if (( TheSr.Name <> '.' ) and ( TheSr.Name <> '..' ) and ( TheResult >= 0 ))
  3365.   then begin
  3366.     if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  3367.      faDirectory ) then
  3368.     begin { A directory }
  3369.       GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3370.        ButtonHLColor , ButtonSColor , TextColor );
  3371.       { If found create a New FileIconPanel on the imported scrollbox }
  3372.       { Note sending 0 ExtraData parameter to indicate file not drive }
  3373.       TheFIP := TFileIconPanel.Create( Self );
  3374.       TheFIP.Parent := Self;
  3375.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  3376.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  3377.         7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor , TargetPath
  3378.          + TheSr.Name , 'MS Serif' , [] , 0 );
  3379.       { Increment column counter and move to New row if past limit }
  3380.       XCounter := XCounter + 1;
  3381.       if XCounter > MaxIconsInARow then
  3382.       begin
  3383.         XCounter := 1;
  3384.         YCounter := YCounter + 1;
  3385.       end;
  3386.     end
  3387.     else
  3388.     begin { A File }
  3389.       { Set up the default color scheme for files }
  3390.       GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3391.        ButtonHLColor , ButtonSColor , TextColor );
  3392.       { If found create a New FileIconPanel on the imported scrollbox }
  3393.       { Note sending 0 ExtraData parameter to indicate file not drive }
  3394.       TheFIP := TFileIconPanel.Create( Self );
  3395.       TheFIP.Parent := Self;
  3396.       TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  3397.        (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize, TheIconSize , 3 ,
  3398.         7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor , TargetPath
  3399.          + TheSr.Name , 'MS Serif' , [] , 0 );
  3400.       { Increment column counter and move to New row if past limit }
  3401.       XCounter := XCounter + 1;
  3402.       if XCounter > MaxIconsInARow then
  3403.       begin
  3404.         XCounter := 1;
  3405.         YCounter := YCounter + 1;
  3406.       end;
  3407.     end;
  3408.   end;
  3409.   { loop through all files in the directory and look for matches }
  3410.   while not Finished do
  3411.   begin
  3412.     { Allow keyboard processing and jump out if c-break hit }
  3413.     Application.ProcessMessages;
  3414.     if GlobalAbortFlag then exit;
  3415.     { Make call to FindNext, using only SearchRecord from FindFirst }
  3416.     TheResult := FindNext( TheSR );
  3417.     { A -1 result means no more files so exit }
  3418.     if TheResult < 0 then finished := true else
  3419.     begin
  3420.       if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory ) =
  3421.        faDirectory ) then
  3422.       begin { A directory }
  3423.         { Set up the blue color scheme for directories }
  3424.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3425.          ButtonHLColor , ButtonSColor , TextColor );
  3426.         { If found create a New FileIconPanel on the imported scrollbox }
  3427.         { Note sending 0 ExtraData parameter to indicate file not drive }
  3428.         TheFIP := TFileIconPanel.Create( Self );
  3429.         TheFIP.Parent := Self;
  3430.         TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  3431.          (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  3432.            7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  3433.             TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  3434.         { Increment column counter and move to New row if past limit }
  3435.         XCounter := XCounter + 1;
  3436.         if XCounter > MaxIconsInARow then
  3437.         begin
  3438.           XCounter := 1;
  3439.           YCounter := YCounter + 1;
  3440.         end;
  3441.       end
  3442.       else
  3443.       begin { A File }
  3444.         { Set up the default color scheme for files }
  3445.         GetColorsForFileIcon( TargetPath + TheSR.Name , ButtonColor ,
  3446.          ButtonHLColor , ButtonSColor , TextColor );
  3447.         { If found create a New FileIconPanel on the imported scrollbox }
  3448.         { Note sending 0 ExtraData parameter to indicate file not drive }
  3449.         TheFIP := TFileIconPanel.Create( Self );
  3450.         TheFIP.Parent := Self;
  3451.         TheFIP.Initialize((( XCounter - 1 ) * TheIconSpacing ),
  3452.          (( YCounter - 1  ) * TheIconSpacing ) , TheIconSize , TheIconSize , 3 ,
  3453.           7 , ButtonColor, ButtonHLColor , ButtonSColor , TextColor ,
  3454.            TargetPath + TheSr.Name , 'MS Serif' , [] , 0 );
  3455.         { Increment column counter and move to New row if past limit }
  3456.         XCounter := XCounter + 1;
  3457.         if XCounter > MaxIconsInARow then
  3458.         begin
  3459.           XCounter := 1;
  3460.           YCounter := YCounter + 1;
  3461.         end;
  3462.       end;
  3463.     end;
  3464.   end;
  3465.   { Call FindClose for Windows NT/Windows 95 compatibility }
  3466.   FindClose( TheSR );
  3467.   { Set up the variables to do recursive calls on all directories}
  3468.   Finished := false;
  3469.   ModifiedDirectory := ExtractFilePath( TheWorkingdirectory ) + '*.*';
  3470.   { Make the call to FindFirst set to get any file, ignore result }
  3471.   TheResult := FindFirst( ModifiedDirectory , faDirectory , TheSR );
  3472.   while not Finished do
  3473.   begin
  3474.     { Allow keyboard input and jump out if c-break hit }
  3475.     Application.ProcessMessages;
  3476.     if GlobalAbortFlag then exit;
  3477.     { Make call to FindNext, using only SearchRecord from FindFirst }
  3478.     TheResult := FindNext( TheSR );
  3479.     { A -1 result means no more files so exit }
  3480.     if TheResult < 0 then finished := true
  3481.     else
  3482.     begin
  3483.       if TheSR.Name <> '..' then { Ignore backup in this case }
  3484.       begin
  3485.         { Do second check due to bug in FindNext }
  3486.         if (( FileGetAttr( TargetPath + TheSR.Name ) and faDirectory )
  3487.         = faDirectory ) then
  3488.         begin
  3489.           { Set up modified directory to recurse into }
  3490.           ModifiedDirectory := ExtractFilePath( TheStoredWorkingDirectory ) +
  3491.            TheSR.Name + '\' + FileMask;
  3492.           { Perform the recursion }
  3493.           RecursiveFileSearch( ModifiedDirectory , XCounter , YCounter );
  3494.         end;
  3495.       end;
  3496.     end;
  3497.   end;
  3498. end;
  3499.  
  3500. begin
  3501.   { Keep the scrollbox from updating during refresh }
  3502.   Visible := false;
  3503.   { Make the clear call }
  3504.   ClearTheFIPs;
  3505.   XCounter := 1;
  3506.   YCounter := 1;
  3507.   { Get the drives for the current machine }
  3508.   AddDriveIcons( XCounter , YCounter );
  3509.   RecursiveFileSearch( TheStartingDirectory , XCounter , YCounter );
  3510.   { Make the scrollbox visible again }
  3511.   Visible := true;
  3512. end;
  3513.  
  3514. end.
  3515.